Skip to content

Commit

Permalink
Merge branch 'chore/stopTestsFromHittingLocalhost' into chore/remove-…
Browse files Browse the repository at this point in the history
…listeners-in-no-listener-test
  • Loading branch information
Christopher Kolstad authored Dec 11, 2023
2 parents 272c082 + 2e1c393 commit ea8e9c0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 5 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package unleash

import (
"fmt"
"time"

"github.com/Unleash/unleash-client-go/v4/api"
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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"},
}))
Expand Down Expand Up @@ -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"},
}))
Expand Down Expand Up @@ -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"},
}))
Expand Down
3 changes: 1 addition & 2 deletions example_bootstrap_from_file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package unleash_test

import (
"fmt"
"io/ioutil"
"os"
"testing"
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/strategies/flexible_rollout_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build norace
// +build norace

package strategies
Expand Down
2 changes: 1 addition & 1 deletion metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions unleash_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package unleash_test

import (
"fmt"
"io/ioutil"
"os"
"testing"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit ea8e9c0

Please sign in to comment.