Skip to content

Commit

Permalink
Bare bones conformance tests that show that the Rest API generation i…
Browse files Browse the repository at this point in the history
…s working correctly
  • Loading branch information
igooch committed Dec 15, 2023
1 parent c4314bc commit 61e094e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
7 changes: 5 additions & 2 deletions build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DEFAULT_CONFORMANCE_TESTS = ready,allocate,setlabel,setannotation,gameserver,hea
ALPHA_CONFORMANCE_TESTS = getplayercapacity,setplayercapacity,playerconnect,playerdisconnect,getplayercount,isplayerconnected,getconnectedplayers
# TODO: Move Counter and List tests into ALPHA_CONFORMANCE_TESTS once the they are written for all SDKs
COUNTS_AND_LISTS_TESTS = getcounter,updatecounter,setcountcounter,setcapacitycounter,getlist,updatelist,addlistvalue,removelistvalue
# TODO: Remove COUNTS_AND_LISTS_REST_TESTS once all conformance tests are written for REST API
COUNTS_AND_LISTS_REST_TESTS = getcounter,updatecounter,getlist,setcapacitycounter,updatelist,addlistvalue,removelistvalue

.PHONY: test-sdks test-sdk build-sdks build-sdk gen-all-sdk-grpc gen-sdk-grpc run-all-sdk-command run-sdk-command build-example

Expand Down Expand Up @@ -192,9 +194,10 @@ run-sdk-conformance-test-csharp:
run-sdk-conformance-test-rest:
# (note: the restapi folder doesn't use GRPC_PORT but run-sdk-conformance-no-build defaults it, so we supply a unique value here)
# run without feature flags
$(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150
# TODO: Uncomment
# $(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150
# run with feature flags enabled
$(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS)
$(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150 FEATURE_GATES=$(ALPHA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_REST_TESTS)

$(MAKE) run-sdk-command COMMAND=clean SDK_FOLDER=restapi

Expand Down
18 changes: 18 additions & 0 deletions pkg/sdkserver/localsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ func (l *LocalSDKServer) GetPlayerCapacity(_ context.Context, _ *alpha.Empty) (*
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) GetCounter(ctx context.Context, in *alpha.GetCounterRequest) (*alpha.Counter, error) {
// TODO: Remove extra logging
l.logger.WithField("GetCounterRequest", in).Info("Getting Counter")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand All @@ -629,6 +632,9 @@ func (l *LocalSDKServer) GetCounter(ctx context.Context, in *alpha.GetCounterReq
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) UpdateCounter(ctx context.Context, in *alpha.UpdateCounterRequest) (*alpha.Counter, error) {
// TODO: Remove extra logging
l.logger.WithField("UpdateCounterRequest", in).Info("Updating Counter")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand Down Expand Up @@ -687,6 +693,9 @@ func (l *LocalSDKServer) UpdateCounter(ctx context.Context, in *alpha.UpdateCoun
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) GetList(ctx context.Context, in *alpha.GetListRequest) (*alpha.List, error) {
// TODO: Remove extra logging
l.logger.WithField("GetListRequest", in).Info("Getting List")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand All @@ -711,6 +720,9 @@ func (l *LocalSDKServer) GetList(ctx context.Context, in *alpha.GetListRequest)
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) UpdateList(ctx context.Context, in *alpha.UpdateListRequest) (*alpha.List, error) {
// TODO: Remove extra logging
l.logger.WithField("UpdateListRequest", in).Info("Updating List")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand Down Expand Up @@ -763,6 +775,9 @@ func (l *LocalSDKServer) UpdateList(ctx context.Context, in *alpha.UpdateListReq
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) AddListValue(ctx context.Context, in *alpha.AddListValueRequest) (*alpha.List, error) {
// TODO: Remove extra logging
l.logger.WithField("AddListValueRequest", in).Info("Adding Value to List")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand Down Expand Up @@ -796,6 +811,9 @@ func (l *LocalSDKServer) AddListValue(ctx context.Context, in *alpha.AddListValu
// [Stage:Alpha]
// [FeatureFlag:CountsAndLists]
func (l *LocalSDKServer) RemoveListValue(ctx context.Context, in *alpha.RemoveListValueRequest) (*alpha.List, error) {
// TODO: Remove extra logging
l.logger.WithField("RemoveListValueRequest", in).Info("Removing Value from List")

if !runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
return nil, errors.Errorf("%s not enabled", runtime.FeatureCountsAndLists)
}
Expand Down
38 changes: 38 additions & 0 deletions test/sdk/restapi/http-api-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,44 @@ func main() {
log.Print("Player Tracking not enabled, skipping.")
}

if strings.Contains(os.Getenv("FEATURE_GATES"), "CountsAndLists=true") {
if counter, _, err := alphaCli.SDKApi.GetCounter(ctx, "conformanceTestCounter"); err != nil {
log.Fatalf("Error getting Counter: %s", err)
} else {
log.Print("Got Counter ", counter)
}

if counter, _, err := alphaCli.SDKApi.UpdateCounter(ctx, alpha.TheRequestedUpdateToMakeToTheCounter{CountDiff: "-1", Capacity: "42"}, "conformanceTestCounter"); err != nil {
log.Fatalf("Error getting Counter: %s", err)
} else {
log.Print("Updated Counter ", counter)
}

if list, _, err := alphaCli.SDKApi.GetList(ctx, "conformanceTestList"); err != nil {
log.Fatalf("Error getting List: %s", err)
} else {
log.Print("Got List ", list)
}

if list, _, err := alphaCli.SDKApi.UpdateList(ctx, alpha.TheListToUpdate{Values: []string{"test123", "test456"}, Capacity: "10"}, "conformanceTestList"); err != nil {
log.Fatalf("Error getting List: %s", err)
} else {
log.Print("Overwritten List ", list)
}

if list, _, err := alphaCli.SDKApi.AddListValue(ctx, alpha.ListsNameaddValueBody{Value: "test789"}, "conformanceTestList"); err != nil {
log.Fatalf("Error getting List: %s", err)
} else {
log.Print("Added Value List ", list)
}

if list, _, err := alphaCli.SDKApi.RemoveListValue(ctx, alpha.ListsNameremoveValueBody{Value: "test456"}, "conformanceTestList"); err != nil {
log.Fatalf("Error getting List: %s", err)
} else {
log.Print("Removed Value List ", list)
}
}

_, _, err = cli.SDKApi.Shutdown(ctx, swagger.SdkEmpty{})
if err != nil {
log.Fatalf("Could not GetGameserver: %v\n", err)
Expand Down

0 comments on commit 61e094e

Please sign in to comment.