diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3dec5d3..d9f3be2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,15 +9,15 @@ jobs: matrix: version: [1.13, 1.15, 1.16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 name: Checkout code - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 name: Checkout client specifications with: repository: Unleash/client-specification ref: refs/tags/v5.1.0 path: testdata/client-specification - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v5 name: Setup go with: go-version: ${{ matrix.version }} diff --git a/client.go b/client.go index 606819f..a2a6c57 100644 --- a/client.go +++ b/client.go @@ -130,11 +130,11 @@ func NewClient(options ...ConfigOption) (*Client, error) { }() if uc.options.url == "" { - return nil, fmt.Errorf("Unleash server URL missing") + return nil, fmt.Errorf("unleash server URL missing") } if strings.HasSuffix(uc.options.url, deprecatedSuffix) { - uc.warn(fmt.Errorf("Unleash server URL %s should no longer link directly to /features", uc.options.url)) + uc.warn(fmt.Errorf("unleash server URL %s should no longer link directly to /features", uc.options.url)) uc.options.url = strings.TrimSuffix(uc.options.url, deprecatedSuffix) } @@ -148,7 +148,7 @@ func NewClient(options ...ConfigOption) (*Client, error) { } if uc.options.appName == "" { - return nil, fmt.Errorf("Unleash client appName missing") + return nil, fmt.Errorf("unleash client appName missing") } if uc.options.instanceId == "" { @@ -358,7 +358,7 @@ func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context cont enabledResult := uc.isEnabled(parent.Feature, WithContext(context)) // According to the schema, if the enabled property is absent we assume it's true. - if parent.Enabled == nil || *parent.Enabled == true { + if parent.Enabled == nil || *parent.Enabled { if parent.Variants != nil && len(*parent.Variants) > 0 && enabledResult.Variant != nil { return enabledResult.Enabled && contains(*parent.Variants, enabledResult.Variant.Name) } @@ -372,11 +372,7 @@ func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context cont return dependenciesSatisfied(parent.(api.Dependency)) }) - if !allDependenciesSatisfied { - return false - } - - return true + return allDependenciesSatisfied } // GetVariant queries a variant as the specified feature is enabled. diff --git a/client_test.go b/client_test.go index c80eb91..ba5331c 100644 --- a/client_test.go +++ b/client_test.go @@ -1,7 +1,6 @@ package unleash import ( - "fmt" "time" "github.com/Unleash/unleash-client-go/v4/api" @@ -35,7 +34,8 @@ func TestClientWithoutListener(t *testing.T) { ) assert.Nil(err, "client should not return an error") - client.Close() + err = client.Close() + assert.Nil(err) assert.True(gock.IsDone(), "there should be no more mocks") } @@ -619,8 +619,6 @@ func TestClient_WithMultipleSegments(t *testing.T) { assert.NoError(err) client.WaitForReady() - fmt.Printf("%v", client.repository.segments) - isEnabled := client.IsEnabled(feature, WithContext(context.Context{ Properties: map[string]string{"custom-id": "custom-ctx", "semver": "3.2.2", "age": "18", "domain": "unleashtest"}, })) @@ -736,8 +734,6 @@ func TestClient_VariantShouldRespectConstraint(t *testing.T) { assert.NoError(err) client.WaitForReady() - fmt.Printf("%v", client.repository.segments) - variant := client.GetVariant(feature, WithVariantContext(context.Context{ Properties: map[string]string{"custom-id": "custom-ctx", "semver": "3.2.2", "age": "18", "domain": "unleashtest"}, })) @@ -853,8 +849,6 @@ func TestClient_VariantShouldFailWhenSegmentConstraintsDontMatch(t *testing.T) { assert.NoError(err) client.WaitForReady() - fmt.Printf("%v", client.repository.segments) - variant := client.GetVariant(feature, WithVariantContext(context.Context{ Properties: map[string]string{"custom-id": "custom-ctx", "semver": "3.2.2", "age": "18", "domain": "unleashtest"}, })) diff --git a/example_bootstrap_from_file_test.go b/example_bootstrap_from_file_test.go index 0c1eadf..8dcf3f6 100644 --- a/example_bootstrap_from_file_test.go +++ b/example_bootstrap_from_file_test.go @@ -1,7 +1,6 @@ package unleash_test import ( - "fmt" "io/ioutil" "os" "testing" @@ -15,6 +14,7 @@ import ( func Test_bootstrapFromFile(t *testing.T) { a := assert.New(t) + defer gock.OffAll() demoReader, err := os.Open("demo_app_toggles.json") if err != nil { t.Fail() @@ -49,7 +49,6 @@ func Test_bootstrapFromFile(t *testing.T) { } enabled := unleash.IsEnabled("DateExample", unleash.WithContext(context.Context{})) - fmt.Printf("feature is enabled? %v\n", enabled) a.True(enabled) err = unleash.Close() a.Nil(err) diff --git a/internal/strategies/flexible_rollout_test.go b/internal/strategies/flexible_rollout_test.go index 7221968..b94077f 100644 --- a/internal/strategies/flexible_rollout_test.go +++ b/internal/strategies/flexible_rollout_test.go @@ -1,3 +1,4 @@ +//go:build norace // +build norace package strategies diff --git a/metrics_test.go b/metrics_test.go index 5e38c02..689d6c5 100644 --- a/metrics_test.go +++ b/metrics_test.go @@ -117,7 +117,7 @@ func TestMetrics_DoPost(t *testing.T) { WithUrl(mockerServer), WithAppName(mockAppName), WithInstanceId(mockInstanceId), - WithListener(mockListener), + WithListener(&DebugListener{}), ) assert.Nil(err, "client should not return an error") diff --git a/unleash_test.go b/unleash_test.go index 145cfab..1bf07a0 100644 --- a/unleash_test.go +++ b/unleash_test.go @@ -1,7 +1,6 @@ package unleash_test import ( - "fmt" "io/ioutil" "os" "testing" @@ -50,7 +49,6 @@ func Test_withVariants(t *testing.T) { } feature := unleash.GetVariant("Demo") - fmt.Printf("feature is %v\n", feature) if feature.Enabled == false { t.Fatalf("Expected feature to be enabled") } @@ -107,7 +105,6 @@ func Test_withVariantsAndANonExistingStrategyName(t *testing.T) { } feature := unleash.GetVariant("AuditLog") - fmt.Printf("feature is %v\n", feature) if feature.Enabled == true { t.Fatalf("Expected feature to be disabled because Environment does not exist as strategy") }