-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathuserid_logging_test.go
More file actions
86 lines (72 loc) · 2.21 KB
/
Copy pathuserid_logging_test.go
File metadata and controls
86 lines (72 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package controller
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher/fleet/integrationtests/utils"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("GitRepo UserID logging", func() {
var (
gitrepo *fleet.GitRepo
namespace string
)
createGitRepo := func(name string, labels map[string]string) {
gitrepo = &fleet.GitRepo{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: labels,
},
Spec: fleet.GitRepoSpec{
Repo: "https://github.com/rancher/fleet-test-data/single-path",
},
}
Expect(k8sClient.Create(ctx, gitrepo)).ToNot(HaveOccurred())
}
BeforeEach(func() {
var err error
namespace, err = utils.NewNamespaceName()
Expect(err).ToNot(HaveOccurred())
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
Expect(k8sClient.Create(ctx, ns)).ToNot(HaveOccurred())
logsBuffer.Reset()
DeferCleanup(func() {
Expect(k8sClient.Delete(ctx, gitrepo)).ToNot(HaveOccurred())
Expect(k8sClient.Delete(ctx, ns)).ToNot(HaveOccurred())
})
})
When("GitRepo has user ID label", func() {
const userID = "user-12345"
BeforeEach(func() {
createGitRepo("test-gitrepo-with-userid", map[string]string{
fleet.CreatedByUserIDLabel: userID,
})
})
It("includes userID in log output", func() {
Eventually(func() string {
return logsBuffer.String()
}, timeout).Should(Or(
ContainSubstring(`"userID":"`+userID+`"`),
ContainSubstring(`"userID": "`+userID+`"`),
))
logs := logsBuffer.String()
Expect(logs).To(ContainSubstring("gitjob"))
Expect(logs).To(ContainSubstring(gitrepo.Name))
})
})
When("GitRepo does not have user ID label", func() {
BeforeEach(func() {
createGitRepo("test-gitrepo-without-userid", nil)
})
It("does not include userID in log output", func() {
Eventually(func() string {
return logsBuffer.String()
}, timeout).Should(ContainSubstring(gitrepo.Name))
logs := logsBuffer.String()
gitrepoLogs := utils.ExtractResourceLogs(logs, gitrepo.Name)
Expect(gitrepoLogs).NotTo(ContainSubstring(`"userID"`))
})
})
})