Skip to content

Commit

Permalink
enable different test
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre committed Dec 8, 2023
1 parent fb1e946 commit 8bbbcf9
Showing 1 changed file with 52 additions and 53 deletions.
105 changes: 52 additions & 53 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,42 @@ import (

"github.com/Unleash/unleash-client-go/v4/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"gopkg.in/h2non/gock.v1"
)

func TestMetrics_RegisterInstance(t *testing.T) {
assert := assert.New(t)
defer gock.OffAll()
// func TestMetrics_RegisterInstance(t *testing.T) {
// assert := assert.New(t)
// defer gock.OffAll()

gock.New(mockerServer).
Post("/client/register").
MatchHeader("UNLEASH-APPNAME", mockAppName).
MatchHeader("UNLEASH-INSTANCEID", mockInstanceId).
Reply(200)
// gock.New(mockerServer).
// Post("/client/register").
// MatchHeader("UNLEASH-APPNAME", mockAppName).
// MatchHeader("UNLEASH-INSTANCEID", mockInstanceId).
// Reply(200)

gock.New(mockerServer).
Get("/client/features").
Reply(200).
JSON(api.FeatureResponse{})
// gock.New(mockerServer).
// Get("/client/features").
// Reply(200).
// JSON(api.FeatureResponse{})

mockListener := &MockedListener{}
mockListener.On("OnReady").Return()
mockListener.On("OnRegistered", mock.AnythingOfType("ClientData"))
// mockListener := &MockedListener{}
// mockListener.On("OnReady").Return()
// mockListener.On("OnRegistered", mock.AnythingOfType("ClientData"))

client, err := NewClient(
WithUrl(mockerServer),
WithAppName(mockAppName),
WithInstanceId(mockInstanceId),
WithListener(mockListener),
)
// client, err := NewClient(
// WithUrl(mockerServer),
// WithAppName(mockAppName),
// WithInstanceId(mockInstanceId),
// WithListener(mockListener),
// )

time.Sleep(1 * time.Second)
client.Close()
// time.Sleep(1 * time.Second)
// client.Close()

assert.Nil(err, "client should not return an error")
// assert.Nil(err, "client should not return an error")

assert.True(gock.IsDone(), "there should be no more mocks")
}
// assert.True(gock.IsDone(), "there should be no more mocks")
// }

// func TestMetrics_VariantsCountToggles(t *testing.T) {
// assert := assert.New(t)
Expand Down Expand Up @@ -124,37 +123,37 @@ func TestMetrics_RegisterInstance(t *testing.T) {
// assert.True(gock.IsDone(), "there should be no more mocks")
// }

// func TestMetrics_DisabledMetrics(t *testing.T) {
// assert := assert.New(t)
// defer gock.OffAll()
func TestMetrics_DisabledMetrics(t *testing.T) {
assert := assert.New(t)
defer gock.OffAll()

// gock.New(mockerServer).
// Get("/client/features").
// Reply(200).
// JSON(api.FeatureResponse{})
gock.New(mockerServer).
Get("/client/features").
Reply(200).
JSON(api.FeatureResponse{})

// mockListener := &MockedListener{}
// mockListener.On("OnReady").Return()
mockListener := &MockedListener{}
mockListener.On("OnReady").Return()

// client, err := NewClient(
// WithUrl(mockerServer),
// WithDisableMetrics(true),
// WithMetricsInterval(100*time.Millisecond),
// WithAppName(mockAppName),
// WithInstanceId(mockInstanceId),
// WithListener(mockListener),
// )
// assert.Nil(err, "client should not return an error")
client, err := NewClient(
WithUrl(mockerServer),
WithDisableMetrics(true),
WithMetricsInterval(100*time.Millisecond),
WithAppName(mockAppName),
WithInstanceId(mockInstanceId),
WithListener(mockListener),
)
assert.Nil(err, "client should not return an error")

// client.WaitForReady()
// client.IsEnabled("foo")
// client.IsEnabled("bar")
// client.IsEnabled("baz")
client.WaitForReady()
client.IsEnabled("foo")
client.IsEnabled("bar")
client.IsEnabled("baz")

// time.Sleep(300 * time.Millisecond)
// client.Close()
// assert.True(gock.IsDone(), "there should be no more mocks")
// }
time.Sleep(300 * time.Millisecond)
client.Close()
assert.True(gock.IsDone(), "there should be no more mocks")
}

// // TestMetrics_SendMetricsFail tests that no metrics are lost if /client/metrics
// // fails temporarily.
Expand Down

0 comments on commit 8bbbcf9

Please sign in to comment.