-
Notifications
You must be signed in to change notification settings - Fork 55
/
example_bootstrap_from_file_test.go
55 lines (49 loc) · 1.32 KB
/
example_bootstrap_from_file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package unleash_test
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/Unleash/unleash-client-go/v4"
"github.com/Unleash/unleash-client-go/v4/context"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
)
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.WithDisableMetrics(true),
unleash.WithStorage(&unleash.BootstrapStorage{Reader: demoReader}),
unleash.WithUrl("http://foo.com"),
)
if err != nil {
t.Fail()
}
enabled := unleash.IsEnabled("DateExample", unleash.WithContext(context.Context{}))
a.True(enabled)
err = unleash.Close()
a.Nil(err)
}