-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean tests usage of endpoints (#158)
* chore: clean tests usage of endpoints Previously, once we hit the feature refresh interval, we saw failed requests against https://localhost:4242, this update replaces all usages in these tests with the gocked url instead of a fake localhost address --------- Co-authored-by: Simon Hornby <[email protected]>
- Loading branch information
Showing
7 changed files
with
94 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
package unleash_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Unleash/unleash-client-go/v4" | ||
"github.com/Unleash/unleash-client-go/v4/context" | ||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/h2non/gock.v1" | ||
) | ||
|
||
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() | ||
} | ||
gock.New("http://foo.com"). | ||
Post("/client/register"). | ||
Persist(). | ||
Reply(200) | ||
// Read the file into a byte slice | ||
featuresReader, err := os.Open("demo_app_toggles.json") | ||
if err != nil { | ||
t.Fail() | ||
} | ||
byteValue, _ := ioutil.ReadAll(featuresReader) | ||
// Convert the byte slice to a string | ||
jsonStr := string(byteValue) | ||
|
||
// Use the string as the body of the Gock request | ||
gock.New("http://foo.com"). | ||
Get("/client/features").Persist().Reply(200).BodyString(jsonStr) | ||
err = unleash.Initialize( | ||
unleash.WithListener(&unleash.DebugListener{}), | ||
unleash.WithAppName("my-application"), | ||
unleash.WithRefreshInterval(5*time.Second), | ||
unleash.WithMetricsInterval(5*time.Second), | ||
unleash.WithDisableMetrics(true), | ||
unleash.WithStorage(&unleash.BootstrapStorage{Reader: demoReader}), | ||
unleash.WithUrl("https://localhost:4242"), | ||
unleash.WithUrl("http://foo.com"), | ||
) | ||
|
||
if err != nil { | ||
t.Fail() | ||
} | ||
|
||
enabled := unleash.IsEnabled("DateExample", unleash.WithContext(context.Context{})) | ||
fmt.Printf("feature is enabled? %v\n", enabled) | ||
if enabled == false { | ||
t.Fatalf("Expected feature to be enabled") | ||
} | ||
a.True(enabled) | ||
err = unleash.Close() | ||
a.Nil(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build norace | ||
// +build norace | ||
|
||
package strategies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters