Skip to content

Commit

Permalink
fixing test in listenerClient_test
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Nov 21, 2024
1 parent 2206912 commit ec340ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
19 changes: 19 additions & 0 deletions chrysom/acquire_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package chrysom

import (
"net/http"

"github.com/stretchr/testify/mock"
)

type MockAquirer struct {
mock.Mock
}

func (m *MockAquirer) AddAuth(req *http.Request) error {
args := m.Called(req)

return args.Error(0)
}
10 changes: 0 additions & 10 deletions chrysom/basicClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ var (
errFails = errors.New("fails")
)

type MockAquirer struct {
mock.Mock
}

func (m *MockAquirer) AddAuth(req *http.Request) error {
args := m.Called(req)

return args.Error(0)
}

func TestValidateBasicConfig(t *testing.T) {
type testCase struct {
Description string
Expand Down
8 changes: 4 additions & 4 deletions chrysom/listenerClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -43,7 +44,6 @@ func TestListenerStartStopPairsParallel(t *testing.T) {
assert.Nil(t, err)
defer close()

t.Run("ParallelGroup", func(t *testing.T) {
for i := 0; i < 20; i++ {
testNumber := i
t.Run(strconv.Itoa(testNumber), func(t *testing.T) {
Expand All @@ -62,7 +62,6 @@ func TestListenerStartStopPairsParallel(t *testing.T) {
fmt.Printf("%d: Done\n", testNumber)
})
}
})

require.Equal(stopped, client.observer.state)
}
Expand Down Expand Up @@ -106,14 +105,15 @@ func newStartStopClient(includeListener bool) (*ListenerClient, func(), error) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Write(getItemsValidPayload())
}))

acquirer := new(MockAquirer)
acquirer.On("AddAuth", mock.Anything).Return(nil)
config := ListenerConfig{
PullInterval: time.Millisecond * 200,
}
if includeListener {
config.Listener = mockListener
}
client, err := NewListenerClient(config, mockMeasures, &BasicClient{})
client, err := NewListenerClient(config, mockMeasures, &BasicClient{auth: acquirer})
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit ec340ab

Please sign in to comment.