Skip to content

Commit

Permalink
squash! minor
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Jan 8, 2024
1 parent 3506375 commit 7ae08c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func TestOfflineMode(t *testing.T) {
assert.Equal(t, fixtures.Feature1ID, allFlags[0].FeatureID)
assert.Equal(t, fixtures.Feature1Value, allFlags[0].Value)

// And GetIdentityFlags should work as well
// And GetIdentityFlags works as well
flags, err = client.GetIdentityFlags(ctx, "test_identity", nil)
assert.NoError(t, err)

Expand All @@ -587,6 +587,7 @@ func TestOfflineHandlerIsUsedWhenRequestFails(t *testing.T) {
}))
defer server.Close()

// When
client := flagsmith.NewClient(fixtures.EnvironmentAPIKey, flagsmith.WithOfflineHandler(offlineHandler),
flagsmith.WithBaseURL(server.URL+"/api/v1/"))

Expand All @@ -601,4 +602,17 @@ func TestOfflineHandlerIsUsedWhenRequestFails(t *testing.T) {
assert.Equal(t, fixtures.Feature1Name, allFlags[0].FeatureName)
assert.Equal(t, fixtures.Feature1ID, allFlags[0].FeatureID)
assert.Equal(t, fixtures.Feature1Value, allFlags[0].Value)

// And GetIdentityFlags works as well
flags, err = client.GetIdentityFlags(ctx, "test_identity", nil)
assert.NoError(t, err)

allFlags = flags.AllFlags()

assert.Equal(t, 1, len(allFlags))

assert.Equal(t, fixtures.Feature1Name, allFlags[0].FeatureName)
assert.Equal(t, fixtures.Feature1ID, allFlags[0].FeatureID)
assert.Equal(t, fixtures.Feature1Value, allFlags[0].Value)

Check failure on line 617 in client_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary trailing newline (whitespace)
}
1 change: 1 addition & 0 deletions offline_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type LocalFileHandler struct {
environment *environments.EnvironmentModel
}

// NewLocalFileHandler creates a new LocalFileHandler with the given path

Check failure on line 18 in offline_handler.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Comment should end in a period (godot)
func NewLocalFileHandler(environmentDocumentPath string) (*LocalFileHandler, error) {
// Read the environment document from the specified path
environmentDocument, err := os.ReadFile(environmentDocumentPath)
Expand Down
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@ func WithProxy(proxyURL string) Option {
}
}

// WithOfflineHandler returns an Option function that sets the offline handler.
func WithOfflineHandler(handler OfflineHandler) Option {
return func(c *Client) {
c.offlineHandler = handler
}
}

// WithOfflineMode returns an Option function that enables the offline mode.
// NOTE: before using this option, you should set the offline handler.
func WithOfflineMode() Option {
return func(c *Client) {
c.config.offlineMode = true
Expand Down

0 comments on commit 7ae08c7

Please sign in to comment.