Skip to content

Commit

Permalink
yeet half the remaining metrics test
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre committed Dec 8, 2023
1 parent 8ba702f commit 3075eb8
Showing 1 changed file with 59 additions and 60 deletions.
119 changes: 59 additions & 60 deletions metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package unleash

import (
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -82,80 +81,80 @@ func TestMetrics_VariantsCountToggles(t *testing.T) {
assert.True(gock.IsDone(), "there should be no more mocks")
}

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

gock.New(mockerServer).
Post("/client/register").
Reply(200)
// gock.New(mockerServer).
// Post("/client/register").
// Reply(200)

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

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

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),
// )

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

m := client.metrics
// m := client.metrics

serverUrl, _ := url.Parse(mockerServer)
res, err := m.doPost(serverUrl, &struct{}{})
client.Close()
// serverUrl, _ := url.Parse(mockerServer)
// res, err := m.doPost(serverUrl, &struct{}{})
// client.Close()

assert.Nil(err, "doPost should not return an error")
assert.Equal(200, res.StatusCode, "statusCode should be 200")
assert.True(gock.IsDone(), "there should be no more mocks")
}
// assert.Nil(err, "doPost should not return an error")
// assert.Equal(200, res.StatusCode, "statusCode should be 200")
// 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 3075eb8

Please sign in to comment.