Skip to content

Commit

Permalink
okay really run just one client test
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre committed Dec 8, 2023
1 parent 4832f4e commit e9dc290
Showing 1 changed file with 87 additions and 94 deletions.
181 changes: 87 additions & 94 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
//go:build norace
// +build norace

package unleash

import (
"time"

"github.com/Unleash/unleash-client-go/v4/api"
"github.com/Unleash/unleash-client-go/v4/context"

"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"gopkg.in/h2non/gock.v1"
)

Expand Down Expand Up @@ -56,112 +49,112 @@ func TestClientWithoutListener(t *testing.T) {
assert.True(gock.IsDone(), "there should be no more mocks")
}

func TestClient_WithFallbackFunc(t *testing.T) {
assert := assert.New(t)
defer gock.OffAll()
// func TestClient_WithFallbackFunc(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{})

feature := "does_not_exist"
// feature := "does_not_exist"

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

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

assert.NoError(err)
// assert.NoError(err)

client.WaitForReady()
// client.WaitForReady()

fallback := func(f string, ctx *context.Context) bool {
return f == feature
}
// fallback := func(f string, ctx *context.Context) bool {
// return f == feature
// }

isEnabled := client.IsEnabled("does_not_exist", WithFallbackFunc(fallback))
assert.True(isEnabled)
// isEnabled := client.IsEnabled("does_not_exist", WithFallbackFunc(fallback))
// assert.True(isEnabled)

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

func TestClient_WithResolver(t *testing.T) {
assert := assert.New(t)
defer gock.OffAll()
// func TestClient_WithResolver(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{})

const feature = "some_special_value"
// const feature = "some_special_value"

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

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

assert.NoError(err)

client.WaitForReady()

resolver := func(featureName string) *api.Feature {
if featureName == feature {
return &api.Feature{
Name: "some_special_value-resolved",
Description: "",
Enabled: true,
Strategies: []api.Strategy{
{
Id: 1,
Name: "default",
},
},
CreatedAt: time.Time{},
Strategy: "default-strategy",
Parameters: nil,
Variants: nil,
}
} else {
t.Fatalf("the feature name passed %s was not the expected one %s", featureName, feature)
return nil
}
}
// assert.NoError(err)

isEnabled := client.IsEnabled(feature, WithResolver(resolver))
assert.True(isEnabled)
// client.WaitForReady()

assert.True(gock.IsDone(), "there should be no more mocks")
}
// resolver := func(featureName string) *api.Feature {
// if featureName == feature {
// return &api.Feature{
// Name: "some_special_value-resolved",
// Description: "",
// Enabled: true,
// Strategies: []api.Strategy{
// {
// Id: 1,
// Name: "default",
// },
// },
// CreatedAt: time.Time{},
// Strategy: "default-strategy",
// Parameters: nil,
// Variants: nil,
// }
// } else {
// t.Fatalf("the feature name passed %s was not the expected one %s", featureName, feature)
// return nil
// }
// }

// isEnabled := client.IsEnabled(feature, WithResolver(resolver))
// assert.True(isEnabled)

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

// func TestClient_ListFeatures(t *testing.T) {
// assert := assert.New(t)
Expand Down

0 comments on commit e9dc290

Please sign in to comment.