Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state wasm using go-plugin features #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wasm-state-go-plugin/test-store/test_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (store TestStore) Init(context.Context, state.InitRequest) (state.InitRespo
}

func (store TestStore) Features(context.Context, state.FeaturesRequest) (state.FeaturesResponse, error) {
return state.FeaturesResponse{Features: []string{}}, nil
return state.FeaturesResponse{Features: []string{"TRANSACTIONAL"}}, nil
}

func (store TestStore) Set(_ context.Context, req state.SetRequest) (state.SetResponse, error) {
Expand Down
Binary file modified wasm-state-go-plugin/test-store/test_store.wasm
Binary file not shown.
24 changes: 23 additions & 1 deletion wasm-state-go-plugin/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,29 @@ func (wasmStore *wasmStore) Close() error {
}

func (wasmStore *wasmStore) Features() []state.Feature {
return []state.Feature{state.FeatureETag, state.FeatureTransactional}
features, err := wasmStore.store.Features(context.Background(), stateWasm.FeaturesRequest{})

if err != nil {
return []state.Feature{}
}

var featuresArray []state.Feature

for _, feature := range features.Features {
switch feature {
case string(state.FeatureETag):
featuresArray = append(featuresArray, state.FeatureETag)
break
case string(state.FeatureTransactional):
featuresArray = append(featuresArray, state.FeatureTransactional)
break
case string(state.FeatureQueryAPI):
featuresArray = append(featuresArray, state.FeatureQueryAPI)
break
}
}

return featuresArray
}

func (wasmStore *wasmStore) Delete(req *state.DeleteRequest) error {
Expand Down
14 changes: 14 additions & 0 deletions wasm-state-go-plugin/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ func TestReadAndWrite(t *testing.T) {
assert.Nil(t, err)
})
}

func TestFeatures(t *testing.T) {
store, err := NewStateWasmStore(logger.NewLogger("test"), "./test-store/test_store.wasm")
assert.Nil(t, err)

store.Init(state.Metadata{})

t.Run("get features", func(t *testing.T) {
features := store.Features()
assert.NotNil(t, features)
assert.Equal(t, 1, len(features))
assert.Equal(t, state.FeatureTransactional, features[0])
})
}