@@ -40,27 +40,63 @@ func TestBooleanEvaluation(t *testing.T) {
40
40
41
41
func TestIntEvaluation (t * testing.T ) {
42
42
defaultValue := int64 (0 )
43
- expectedValue := int64 (123 )
44
- resolution := provider .IntEvaluation (context .Background (), "int-flag" , defaultValue , nil )
45
- enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
46
- if ! enabled {
47
- t .Fatalf ("Expected feature to be enabled" )
48
- }
49
- if resolution .ProviderResolutionDetail .Variant != "aaaa" {
50
- t .Fatalf ("Expected variant name" )
51
- }
52
- if resolution .Value != expectedValue {
53
- t .Fatalf ("Expected one of the variant payloads" )
54
- }
55
43
56
- t .Run ("evalCtx empty" , func (t * testing.T ) {
57
- resolution := provider .IntEvaluation (context .Background (), "non-existing-flag" , defaultValue , nil )
44
+ t .Run ("int-flag" , func (t * testing.T ) {
45
+ resolution := provider .IntEvaluation (context .Background (), "int-flag" , defaultValue , nil )
46
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
47
+ require .True (t , enabled )
48
+ require .Equal (t , "int-flag-variant" , resolution .ProviderResolutionDetail .Variant )
49
+ require .Equal (t , int64 (123 ), resolution .Value )
50
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
51
+ })
52
+
53
+ t .Run ("disabled-flag" , func (t * testing.T ) {
54
+ resolution := provider .IntEvaluation (context .Background (), "disabled-flag" , defaultValue , nil )
55
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
56
+ require .False (t , enabled )
57
+ require .Equal (t , "" , resolution .ProviderResolutionDetail .Variant )
58
58
require .Equal (t , defaultValue , resolution .Value )
59
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
59
60
})
60
61
61
- t .Run ("evalCtx empty fallback to default " , func (t * testing.T ) {
62
+ t .Run ("non-existing-flag " , func (t * testing.T ) {
62
63
resolution := provider .IntEvaluation (context .Background (), "non-existing-flag" , defaultValue , nil )
64
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
65
+ require .False (t , enabled )
66
+ require .Equal (t , "" , resolution .ProviderResolutionDetail .Variant )
67
+ require .Equal (t , defaultValue , resolution .Value )
68
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
69
+ })
70
+ }
71
+
72
+ func TestFloatEvaluation (t * testing.T ) {
73
+ defaultValue := 0.0
74
+
75
+ t .Run ("int-flag" , func (t * testing.T ) {
76
+ resolution := provider .FloatEvaluation (context .Background (), "double-flag" , defaultValue , nil )
77
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
78
+ require .True (t , enabled )
79
+ require .Equal (t , "double-flag-variant" , resolution .ProviderResolutionDetail .Variant )
80
+ require .Equal (t , 1.23 , resolution .Value )
81
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
82
+ })
83
+
84
+ t .Run ("disabled-flag" , func (t * testing.T ) {
85
+ resolution := provider .FloatEvaluation (context .Background (), "disabled-flag" , defaultValue , nil )
86
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
87
+ require .False (t , enabled )
88
+ require .Equal (t , "" , resolution .ProviderResolutionDetail .Variant )
89
+ require .Equal (t , defaultValue , resolution .Value )
90
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
91
+ })
92
+
93
+ t .Run ("non-existing-flag" , func (t * testing.T ) {
94
+ resolution := provider .FloatEvaluation (context .Background (), "non-existing-flag" , defaultValue , nil )
95
+ enabled , _ := resolution .ProviderResolutionDetail .FlagMetadata .GetBool ("enabled" )
96
+ require .False (t , enabled )
97
+ require .Equal (t , "" , resolution .ProviderResolutionDetail .Variant )
63
98
require .Equal (t , defaultValue , resolution .Value )
99
+ require .Equal (t , of .ErrorCode ("" ), resolution .ResolutionDetail ().ErrorCode )
64
100
})
65
101
}
66
102
@@ -228,13 +264,17 @@ func TestMain(m *testing.M) {
228
264
}
229
265
defer demoReader .Close ()
230
266
267
+ appName := "my-application"
268
+ backupFile := fmt .Sprintf ("unleash-repo-schema-v1-%s.json" , appName )
269
+
231
270
providerOptions := unleashProvider.ProviderConfig {
232
271
Options : []unleash.ConfigOption {
233
272
unleash .WithListener (& unleash.DebugListener {}),
234
- unleash .WithAppName ("my-application" ),
273
+ unleash .WithAppName (appName ),
235
274
unleash .WithRefreshInterval (5 * time .Second ),
236
275
unleash .WithMetricsInterval (5 * time .Second ),
237
276
unleash .WithStorage (& unleash.BootstrapStorage {Reader : demoReader }),
277
+ unleash .WithBackupPath ("./" ),
238
278
unleash .WithUrl ("https://localhost:4242" ),
239
279
},
240
280
}
@@ -258,5 +298,6 @@ func TestMain(m *testing.M) {
258
298
259
299
cleanup ()
260
300
301
+ os .Remove (backupFile )
261
302
os .Exit (exitCode )
262
303
}
0 commit comments