Skip to content

Commit

Permalink
fixed github issue 3819 for endpoint customizer tests (#3823)
Browse files Browse the repository at this point in the history
* fixed github issue 3819 for endpoint customizer tests

* added negative test cases

* improved comments

* using ahrav's approach
  • Loading branch information
kashifkhan0771 authored Dec 31, 2024
1 parent def734a commit e98dfa5
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions pkg/detectors/endpoint_customizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

}

0 comments on commit e98dfa5

Please sign in to comment.