Skip to content

Commit e98dfa5

Browse files
fixed github issue 3819 for endpoint customizer tests (#3823)
* fixed github issue 3819 for endpoint customizer tests * added negative test cases * improved comments * using ahrav's approach
1 parent def734a commit e98dfa5

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

pkg/detectors/endpoint_customizer_test.go

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,53 @@ import (
88

99
func TestEmbeddedEndpointSetter(t *testing.T) {
1010
type Scanner struct{ EndpointSetter }
11+
1112
var s Scanner
12-
assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
13-
assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
14-
assert.Error(t, s.SetConfiguredEndpoints())
15-
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("baz"))
13+
14+
t.Run("useFoundEndpoints is true", func(t *testing.T) {
15+
s.useFoundEndpoints = true
16+
17+
// "baz" is passed to Endpoints, should appear in the result
18+
assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
19+
})
20+
21+
t.Run("setting configured endpoints", func(t *testing.T) {
22+
// Setting "foo" and "bar"
23+
assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
24+
25+
// Returning error because no endpoints are passed
26+
assert.Error(t, s.SetConfiguredEndpoints())
27+
})
28+
29+
// "foo" and "bar" are added as configured endpoint
30+
31+
t.Run("useFoundEndpoints adds new endpoints", func(t *testing.T) {
32+
// "baz" is added because useFoundEndpoints is true
33+
assert.Equal(t, []string{"foo", "bar", "baz"}, s.Endpoints("baz"))
34+
})
35+
36+
t.Run("useCloudEndpoint is true", func(t *testing.T) {
37+
s.useCloudEndpoint = true
38+
s.cloudEndpoint = "test"
39+
40+
// "test" is added because useCloudEndpoint is true and cloudEndpoint is set
41+
assert.Equal(t, []string{"foo", "bar", "test"}, s.Endpoints())
42+
})
43+
44+
t.Run("disable both foundEndpoints and cloudEndpoint", func(t *testing.T) {
45+
// now disable both useFoundEndpoints and useCloudEndpoint
46+
s.useFoundEndpoints = false
47+
s.useCloudEndpoint = false
48+
49+
// "test" won't be added
50+
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("test"))
51+
})
52+
53+
t.Run("cloudEndpoint not added when useCloudEndpoint is false", func(t *testing.T) {
54+
s.cloudEndpoint = "new"
55+
56+
// "new" is not added because useCloudEndpoint is false
57+
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints())
58+
})
59+
1660
}

0 commit comments

Comments
 (0)