-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: flagd offline in-process support with flags sources from file (#…
…421) Signed-off-by: Kavindu Dodanduwa <[email protected]> Signed-off-by: Kavindu Dodanduwa <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
- Loading branch information
1 parent
e9dde7a
commit 8685cc0
Showing
7 changed files
with
149 additions
and
46 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
53 changes: 53 additions & 0 deletions
53
providers/flagd/pkg/service/in_process/service_file_test.go
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package process | ||
|
||
import ( | ||
"context" | ||
of "github.com/open-feature/go-sdk/openfeature" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestInProcessOfflineMode(t *testing.T) { | ||
// given | ||
flagFile := "config.json" | ||
offlinePath := filepath.Join(t.TempDir(), flagFile) | ||
|
||
err := os.WriteFile(offlinePath, []byte(flagRsp), 0644) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// when | ||
service := NewInProcessService(Configuration{OfflineFlagSource: offlinePath}) | ||
|
||
err = service.Init() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// then | ||
channel := service.EventChannel() | ||
|
||
select { | ||
case event := <-channel: | ||
if event.EventType != of.ProviderReady { | ||
t.Fatalf("Provider initialization failed. Got event type %s with message %s", event.EventType, event.Message) | ||
} | ||
case <-time.After(2 * time.Second): | ||
t.Fatal("Provider initialization did not complete within acceptable timeframe ") | ||
} | ||
|
||
// provider must evaluate flag from the grpc source data | ||
detail := service.ResolveBoolean(context.Background(), "myBoolFlag", false, make(map[string]interface{})) | ||
|
||
if !detail.Value { | ||
t.Fatal("Expected true, but got false") | ||
} | ||
|
||
// check for metadata - scope from grpc sync | ||
if len(detail.FlagMetadata) == 0 && detail.FlagMetadata["scope"] == "" { | ||
t.Fatal("Expected scope to be present, but got none") | ||
} | ||
} |
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