Skip to content

Find, verify, and analyze leaked credentials

fixed github issue 3819 for endpoint customizer tests (#3823)

Kashif Khane98dfa50f8f3
diff --git a/pkg/detectors/endpoint_customizer_test.go b/pkg/detectors/endpoint_customizer_test.go
index 229cf915a..0f54118b5 100644
--- a/pkg/detectors/endpoint_customizer_test.go
+++ b/pkg/detectors/endpoint_customizer_test.go
@@ -8,9 +8,53 @@ import (
func TestEmbeddedEndpointSetter(t *testing.T) {
type Scanner struct{ EndpointSetter }
+
var s Scanner
- assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
- assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
- assert.Error(t, s.SetConfiguredEndpoints())
- assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("baz"))
+
+ t.Run("useFoundEndpoints is true", func(t *testing.T) {
+ s.useFoundEndpoints = true
+
+ // "baz" is passed to Endpoints, should appear in the result
+ assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
+ })
+
+ t.Run("setting configured endpoints", func(t *testing.T) {
+ // Setting "foo" and "bar"
+ assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
+
+ // Returning error because no endpoints are passed
+ assert.Error(t, s.SetConfiguredEndpoints())
+ })
+
+ // "foo" and "bar" are added as configured endpoint
+
+ t.Run("useFoundEndpoints adds new endpoints", func(t *testing.T) {
+ // "baz" is added because useFoundEndpoints is true
+ assert.Equal(t, []string{"foo", "bar", "baz"}, s.Endpoints("baz"))
+ })
+
+ t.Run("useCloudEndpoint is true", func(t *testing.T) {
+ s.useCloudEndpoint = true
+ s.cloudEndpoint = "test"
+
+ // "test" is added because useCloudEndpoint is true and cloudEndpoint is set
+ assert.Equal(t, []string{"foo", "bar", "test"}, s.Endpoints())
+ })
+
+ t.Run("disable both foundEndpoints and cloudEndpoint", func(t *testing.T) {
+ // now disable both useFoundEndpoints and useCloudEndpoint
+ s.useFoundEndpoints = false
+ s.useCloudEndpoint = false
+
+ // "test" won't be added
+ assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("test"))
+ })
+
+ t.Run("cloudEndpoint not added when useCloudEndpoint is false", func(t *testing.T) {
+ s.cloudEndpoint = "new"
+
+ // "new" is not added because useCloudEndpoint is false
+ assert.Equal(t, []string{"foo", "bar"}, s.Endpoints())
+ })
+
}