diff --git a/sdks/go/alpha.go b/sdks/go/alpha.go index 8ddb9a8bf8..6fb2fd30ef 100644 --- a/sdks/go/alpha.go +++ b/sdks/go/alpha.go @@ -17,35 +17,36 @@ package sdk import ( "context" - "github.com/pkg/errors" "google.golang.org/grpc" "agones.dev/agones/pkg/sdk/alpha" + "agones.dev/agones/pkg/util/errors" ) // Alpha is the struct for Alpha SDK functionality. type Alpha struct { client alpha.SDKClient + errs *errors.Errors } // newAlpha creates a new Alpha SDK with the passed in connection. func newAlpha(conn *grpc.ClientConn) *Alpha { - return &Alpha{ - client: alpha.NewSDKClient(conn), - } + a := &Alpha{client: alpha.NewSDKClient(conn)} + a.errs = errors.FromStruct(a) + return a } // GetPlayerCapacity gets the last player capacity that was set through the SDK. // If the player capacity is set from outside the SDK, use SDK.GameServer() instead. func (a *Alpha) GetPlayerCapacity() (int64, error) { c, err := a.client.GetPlayerCapacity(context.Background(), &alpha.Empty{}) - return c.GetCount(), errors.Wrap(err, "could not get player capacity") + return c.GetCount(), a.errs.Wrap(err, "could not get player capacity") } // SetPlayerCapacity changes the player capacity to a new value. func (a *Alpha) SetPlayerCapacity(capacity int64) error { _, err := a.client.SetPlayerCapacity(context.Background(), &alpha.Count{Count: capacity}) - return errors.Wrap(err, "could not set player capacity") + return a.errs.Wrap(err, "could not set player capacity") } // PlayerConnect increases the SDK’s stored player count by one, and appends this playerID to status.players.id. @@ -53,7 +54,7 @@ func (a *Alpha) SetPlayerCapacity(capacity int64) error { // list of connected playerIDs. func (a *Alpha) PlayerConnect(id string) (bool, error) { ok, err := a.client.PlayerConnect(context.Background(), &alpha.PlayerID{PlayerID: id}) - return ok.GetBool(), errors.Wrap(err, "could not register connected player") + return ok.GetBool(), a.errs.Wrap(err, "could not register connected player") } // PlayerDisconnect Decreases the SDK’s stored player count by one, and removes the playerID from status.players.id. @@ -61,25 +62,25 @@ func (a *Alpha) PlayerConnect(id string) (bool, error) { // playerID value exists within the list. func (a *Alpha) PlayerDisconnect(id string) (bool, error) { ok, err := a.client.PlayerDisconnect(context.Background(), &alpha.PlayerID{PlayerID: id}) - return ok.GetBool(), errors.Wrap(err, "could not register disconnected player") + return ok.GetBool(), a.errs.Wrap(err, "could not register disconnected player") } // GetPlayerCount returns the current player count. func (a *Alpha) GetPlayerCount() (int64, error) { count, err := a.client.GetPlayerCount(context.Background(), &alpha.Empty{}) - return count.GetCount(), errors.Wrap(err, "could not get player count") + return count.GetCount(), a.errs.Wrap(err, "could not get player count") } // IsPlayerConnected returns if the playerID is currently connected to the GameServer. // This is always accurate, even if the value hasn’t been updated to the GameServer status yet. func (a *Alpha) IsPlayerConnected(id string) (bool, error) { ok, err := a.client.IsPlayerConnected(context.Background(), &alpha.PlayerID{PlayerID: id}) - return ok.GetBool(), errors.Wrap(err, "could not get if player is connected") + return ok.GetBool(), a.errs.Wrap(err, "could not get if player is connected") } // GetConnectedPlayers returns the list of the currently connected player ids. // This is always accurate, even if the value hasn’t been updated to the GameServer status yet. func (a *Alpha) GetConnectedPlayers() ([]string, error) { list, err := a.client.GetConnectedPlayers(context.Background(), &alpha.Empty{}) - return list.GetList(), errors.Wrap(err, "could not list connected players") + return list.GetList(), a.errs.Wrap(err, "could not list connected players") } diff --git a/sdks/go/beta.go b/sdks/go/beta.go index 46ce4dbc27..4d2f5e4278 100644 --- a/sdks/go/beta.go +++ b/sdks/go/beta.go @@ -17,24 +17,25 @@ package sdk import ( "context" - "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/fieldmaskpb" "google.golang.org/protobuf/types/known/wrapperspb" "agones.dev/agones/pkg/sdk/beta" + "agones.dev/agones/pkg/util/errors" ) // Beta is the struct for Beta SDK functionality. type Beta struct { client beta.SDKClient + errs *errors.Errors } // newBeta creates a new Beta SDK with the passed in connection. func newBeta(conn *grpc.ClientConn) *Beta { - return &Beta{ - client: beta.NewSDKClient(conn), - } + b := &Beta{client: beta.NewSDKClient(conn)} + b.errs = errors.FromStruct(b) + return b } // GetCounterCount returns the Count for a Counter, given the Counter's key (name). @@ -42,7 +43,7 @@ func newBeta(conn *grpc.ClientConn) *Beta { func (b *Beta) GetCounterCount(key string) (int64, error) { counter, err := b.client.GetCounter(context.Background(), &beta.GetCounterRequest{Name: key}) if err != nil { - return -1, errors.Wrapf(err, "could not get Counter %s count", key) + return -1, b.errs.Wrapf(err, "could not get Counter %s count", key) } return counter.Count, nil } @@ -58,7 +59,7 @@ func (b *Beta) GetCounterCount(key string) (int64, error) { // value is batched asynchronous any value incremented past the capacity will be silently truncated. func (b *Beta) IncrementCounter(key string, amount int64) error { if amount < 0 { - return errors.Errorf("amount must be a positive int64, found %d", amount) + return b.errs.Errorf("amount must be a positive int64, found %d", amount) } _, err := b.client.UpdateCounter(context.Background(), &beta.UpdateCounterRequest{ CounterUpdateRequest: &beta.CounterUpdateRequest{ @@ -66,7 +67,7 @@ func (b *Beta) IncrementCounter(key string, amount int64) error { CountDiff: amount, }}) if err != nil { - return errors.Wrapf(err, "could not increment Counter %s by amount %d", key, amount) + return b.errs.Wrapf(err, "could not increment Counter %s by amount %d", key, amount) } return nil } @@ -76,7 +77,7 @@ func (b *Beta) IncrementCounter(key string, amount int64) error { // Will error if the count is at 0 (to the latest knowledge of the SDK), and no decrement will occur. func (b *Beta) DecrementCounter(key string, amount int64) error { if amount < 0 { - return errors.Errorf("amount must be a positive int64, found %d", amount) + return b.errs.Errorf("amount must be a positive int64, found %d", amount) } _, err := b.client.UpdateCounter(context.Background(), &beta.UpdateCounterRequest{ CounterUpdateRequest: &beta.CounterUpdateRequest{ @@ -84,7 +85,7 @@ func (b *Beta) DecrementCounter(key string, amount int64) error { CountDiff: amount * -1, }}) if err != nil { - return errors.Wrapf(err, "could not decrement Counter %s by amount %d", key, amount) + return b.errs.Wrapf(err, "could not decrement Counter %s by amount %d", key, amount) } return nil } @@ -98,7 +99,7 @@ func (b *Beta) SetCounterCount(key string, amount int64) error { Count: wrapperspb.Int64(amount), }}) if err != nil { - return errors.Wrapf(err, "could not set Counter %s count to amount %d", key, amount) + return b.errs.Wrapf(err, "could not set Counter %s count to amount %d", key, amount) } return nil } @@ -108,7 +109,7 @@ func (b *Beta) SetCounterCount(key string, amount int64) error { func (b *Beta) GetCounterCapacity(key string) (int64, error) { counter, err := b.client.GetCounter(context.Background(), &beta.GetCounterRequest{Name: key}) if err != nil { - return -1, errors.Wrapf(err, "could not get Counter %s capacity", key) + return -1, b.errs.Wrapf(err, "could not get Counter %s capacity", key) } return counter.Capacity, nil } @@ -121,7 +122,7 @@ func (b *Beta) SetCounterCapacity(key string, amount int64) error { Capacity: wrapperspb.Int64(amount), }}) if err != nil { - return errors.Wrapf(err, "could not set Counter %s capacity to amount %d", key, amount) + return b.errs.Wrapf(err, "could not set Counter %s capacity to amount %d", key, amount) } return nil } @@ -131,7 +132,7 @@ func (b *Beta) SetCounterCapacity(key string, amount int64) error { func (b *Beta) GetListCapacity(key string) (int64, error) { list, err := b.client.GetList(context.Background(), &beta.GetListRequest{Name: key}) if err != nil { - return -1, errors.Wrapf(err, "could not get List %s", key) + return -1, b.errs.Wrapf(err, "could not get List %s", key) } return list.Capacity, nil } @@ -147,7 +148,7 @@ func (b *Beta) SetListCapacity(key string, amount int64) error { UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"capacity"}}, }) if err != nil { - return errors.Wrapf(err, "could not set List %s capacity to amount %d", key, amount) + return b.errs.Wrapf(err, "could not set List %s capacity to amount %d", key, amount) } return nil } @@ -158,7 +159,7 @@ func (b *Beta) SetListCapacity(key string, amount int64) error { func (b *Beta) ListContains(key, value string) (bool, error) { list, err := b.client.GetList(context.Background(), &beta.GetListRequest{Name: key}) if err != nil { - return false, errors.Wrapf(err, "could not get List %s", key) + return false, b.errs.Wrapf(err, "could not get List %s", key) } for _, val := range list.Values { if val == value { @@ -173,7 +174,7 @@ func (b *Beta) ListContains(key, value string) (bool, error) { func (b *Beta) GetListLength(key string) (int, error) { list, err := b.client.GetList(context.Background(), &beta.GetListRequest{Name: key}) if err != nil { - return -1, errors.Wrapf(err, "could not get List %s", key) + return -1, b.errs.Wrapf(err, "could not get List %s", key) } return len(list.Values), nil } @@ -183,7 +184,7 @@ func (b *Beta) GetListLength(key string) (int, error) { func (b *Beta) GetListValues(key string) ([]string, error) { list, err := b.client.GetList(context.Background(), &beta.GetListRequest{Name: key}) if err != nil { - return nil, errors.Wrapf(err, "could not get List %s", key) + return nil, b.errs.Wrapf(err, "could not get List %s", key) } return list.Values, nil } @@ -194,7 +195,7 @@ func (b *Beta) GetListValues(key string) ([]string, error) { func (b *Beta) AppendListValue(key, value string) error { _, err := b.client.AddListValue(context.Background(), &beta.AddListValueRequest{Name: key, Value: value}) if err != nil { - return errors.Wrapf(err, "could not get List %s", key) + return b.errs.Wrapf(err, "could not get List %s", key) } return nil } @@ -205,7 +206,7 @@ func (b *Beta) AppendListValue(key, value string) error { func (b *Beta) DeleteListValue(key, value string) error { _, err := b.client.RemoveListValue(context.Background(), &beta.RemoveListValueRequest{Name: key, Value: value}) if err != nil { - return errors.Wrapf(err, "could not get List %s", key) + return b.errs.Wrapf(err, "could not get List %s", key) } return nil } diff --git a/sdks/go/beta_test.go b/sdks/go/beta_test.go index 04f354abc2..8f8c1c3bd6 100644 --- a/sdks/go/beta_test.go +++ b/sdks/go/beta_test.go @@ -16,13 +16,14 @@ package sdk import ( "context" + "fmt" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "agones.dev/agones/pkg/sdk/beta" + "agones.dev/agones/pkg/util/errors" ) func TestBetaGetAndUpdateCounter(t *testing.T) { @@ -65,6 +66,7 @@ func TestBetaGetAndUpdateCounter(t *testing.T) { b := Beta{ client: mock, } + b.errs = errors.FromStruct(&b) t.Parallel() @@ -206,6 +208,7 @@ func TestBetaGetAndUpdateList(t *testing.T) { b := Beta{ client: mock, } + b.errs = errors.FromStruct(&b) t.Parallel() @@ -286,7 +289,7 @@ func (b *betaMock) GetCounter(_ context.Context, in *beta.GetCounterRequest, _ . if counter, ok := b.counters[in.Name]; ok { return counter, nil } - return nil, errors.Errorf("counter not found: %s", in.Name) + return nil, fmt.Errorf("counter not found: %s", in.Name) } func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequest, _ ...grpc.CallOption) (*beta.Counter, error) { @@ -299,23 +302,23 @@ func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequ case in.CounterUpdateRequest.CountDiff != 0: count := counter.Count + in.CounterUpdateRequest.CountDiff if count < 0 || count > counter.Capacity { - return nil, errors.Errorf("out of range. Count must be within range [0,Capacity]. Found Count: %d, Capacity: %d", count, counter.Capacity) + return nil, fmt.Errorf("out of range. Count must be within range [0,Capacity]. Found Count: %d, Capacity: %d", count, counter.Capacity) } counter.Count = count case in.CounterUpdateRequest.Count != nil: countSet := in.CounterUpdateRequest.Count.GetValue() if countSet < 0 || countSet > counter.Capacity { - return nil, errors.Errorf("out of range. Count must be within range [0,Capacity]. Found Count: %d, Capacity: %d", countSet, counter.Capacity) + return nil, fmt.Errorf("out of range. Count must be within range [0,Capacity]. Found Count: %d, Capacity: %d", countSet, counter.Capacity) } counter.Count = countSet case in.CounterUpdateRequest.Capacity != nil: capacity := in.CounterUpdateRequest.Capacity.GetValue() if capacity < 0 { - return nil, errors.Errorf("out of range. Capacity must be greater than or equal to 0. Found Capacity: %d", capacity) + return nil, fmt.Errorf("out of range. Capacity must be greater than or equal to 0. Found Capacity: %d", capacity) } counter.Capacity = capacity default: - return nil, errors.Errorf("invalid argument. Malformed CounterUpdateRequest: %v", + return nil, fmt.Errorf("invalid argument. Malformed CounterUpdateRequest: %v", in.CounterUpdateRequest) } @@ -327,26 +330,26 @@ func (b *betaMock) UpdateCounter(ctx context.Context, in *beta.UpdateCounterRequ // a list with any pending batched changes applied. func (b *betaMock) GetList(_ context.Context, in *beta.GetListRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { - return nil, errors.Errorf("GetListRequest cannot be nil") + return nil, fmt.Errorf("GetListRequest cannot be nil") } if list, ok := b.lists[in.Name]; ok { return list, nil } - return nil, errors.Errorf("list not found: %s", in.Name) + return nil, fmt.Errorf("list not found: %s", in.Name) } // Note: unlike the SDK Server, UpdateList does not batch changes and instead updates the list // directly. func (b *betaMock) UpdateList(_ context.Context, in *beta.UpdateListRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { - return nil, errors.Errorf("UpdateListRequest cannot be nil") + return nil, fmt.Errorf("UpdateListRequest cannot be nil") } list, ok := b.lists[in.List.Name] if !ok { - return nil, errors.Errorf("list not found: %s", in.List.Name) + return nil, fmt.Errorf("list not found: %s", in.List.Name) } if in.List.Capacity < 0 || in.List.Capacity > 1000 { - return nil, errors.Errorf("out of range. Capacity must be within range [0,1000]. Found Capacity: %d", in.List.Capacity) + return nil, fmt.Errorf("out of range. Capacity must be within range [0,1000]. Found Capacity: %d", in.List.Capacity) } list.Capacity = in.List.Capacity if len(list.Values) > int(list.Capacity) { @@ -360,18 +363,18 @@ func (b *betaMock) UpdateList(_ context.Context, in *beta.UpdateListRequest, _ . // directly. func (b *betaMock) AddListValue(_ context.Context, in *beta.AddListValueRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { - return nil, errors.Errorf("AddListValueRequest cannot be nil") + return nil, fmt.Errorf("AddListValueRequest cannot be nil") } list, ok := b.lists[in.Name] if !ok { - return nil, errors.Errorf("list not found: %s", in.Name) + return nil, fmt.Errorf("list not found: %s", in.Name) } if int(list.Capacity) <= len(list.Values) { - return nil, errors.Errorf("out of range. No available capacity. Current Capacity: %d, List Size: %d", list.Capacity, len(list.Values)) + return nil, fmt.Errorf("out of range. No available capacity. Current Capacity: %d, List Size: %d", list.Capacity, len(list.Values)) } for _, val := range list.Values { if in.Value == val { - return nil, errors.Errorf("already exists. Value: %s already in List: %s", in.Value, in.Name) + return nil, fmt.Errorf("already exists. Value: %s already in List: %s", in.Value, in.Name) } } list.Values = append(list.Values, in.Value) @@ -383,11 +386,11 @@ func (b *betaMock) AddListValue(_ context.Context, in *beta.AddListValueRequest, // directly. func (b *betaMock) RemoveListValue(_ context.Context, in *beta.RemoveListValueRequest, _ ...grpc.CallOption) (*beta.List, error) { if in == nil { - return nil, errors.Errorf("RemoveListValueRequest cannot be nil") + return nil, fmt.Errorf("RemoveListValueRequest cannot be nil") } list, ok := b.lists[in.Name] if !ok { - return nil, errors.Errorf("list not found: %s", in.Name) + return nil, fmt.Errorf("list not found: %s", in.Name) } for i, val := range list.Values { if in.Value != val { @@ -397,5 +400,5 @@ func (b *betaMock) RemoveListValue(_ context.Context, in *beta.RemoveListValueRe b.lists[in.Name] = list return &beta.List{}, nil } - return nil, errors.Errorf("not found. Value: %s not found in List: %s", in.Value, in.Name) + return nil, fmt.Errorf("not found. Value: %s not found in List: %s", in.Value, in.Name) } diff --git a/sdks/go/sdk.go b/sdks/go/sdk.go index 5068fb0f3f..d60f63424f 100644 --- a/sdks/go/sdk.go +++ b/sdks/go/sdk.go @@ -17,17 +17,17 @@ package sdk import ( "context" + stderrors "errors" "fmt" "io" "os" "time" - "github.com/pkg/errors" - "google.golang.org/grpc/credentials/insecure" + "agones.dev/agones/pkg/sdk" + "agones.dev/agones/pkg/util/errors" "google.golang.org/grpc" - - "agones.dev/agones/pkg/sdk" + "google.golang.org/grpc/credentials/insecure" ) // GameServerCallback is a function definition to be called @@ -41,6 +41,7 @@ type SDK struct { health sdk.SDK_HealthClient alpha *Alpha beta *Beta + errs *errors.Errors } // ErrorLog is a function to log the error. @@ -69,19 +70,20 @@ func NewSDK() (*SDK, error) { s := &SDK{ ctx: context.Background(), } + s.errs = errors.FromStruct(s) // Block for at least 30 seconds. ctx, cancel := context.WithTimeout(s.ctx, 30*time.Second) defer cancel() // nolint: staticcheck conn, err := grpc.DialContext(ctx, addr, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - return s, errors.Wrapf(err, "could not connect to %s", addr) + return s, s.errs.Wrapf(err, "could not connect to %s", addr) } s.client = sdk.NewSDKClient(conn) s.health, err = s.client.Health(s.ctx) s.alpha = newAlpha(conn) s.beta = newBeta(conn) - return s, errors.Wrap(err, "could not set up health check") + return s, s.errs.Wrap(err, "could not set up health check") } // Alpha returns the Alpha SDK. @@ -97,19 +99,19 @@ func (s *SDK) Beta() *Beta { // Ready marks the Game Server as ready to receive connections. func (s *SDK) Ready() error { _, err := s.client.Ready(s.ctx, &sdk.Empty{}) - return errors.Wrap(err, "could not send Ready message") + return s.errs.Wrap(err, "could not send Ready message") } // Allocate self marks this gameserver as Allocated. func (s *SDK) Allocate() error { _, err := s.client.Allocate(s.ctx, &sdk.Empty{}) - return errors.Wrap(err, "could not mark self as Allocated") + return s.errs.Wrap(err, "could not mark self as Allocated") } // Shutdown marks the Game Server as ready to shutdown. func (s *SDK) Shutdown() error { _, err := s.client.Shutdown(s.ctx, &sdk.Empty{}) - return errors.Wrapf(err, "could not send Shutdown message") + return s.errs.Wrap(err, "could not send Shutdown message") } // Reserve marks the Game Server as Reserved for a given duration, at which point @@ -117,32 +119,32 @@ func (s *SDK) Shutdown() error { // Do note, the smallest unit available in the time.Duration argument is a second. func (s *SDK) Reserve(d time.Duration) error { _, err := s.client.Reserve(s.ctx, &sdk.Duration{Seconds: int64(d.Seconds())}) - return errors.Wrap(err, "could not send Reserve message") + return s.errs.Wrap(err, "could not send Reserve message") } // Health sends a ping to the sidecar health check to indicate that this Game Server is healthy. func (s *SDK) Health() error { - return errors.Wrap(s.health.Send(&sdk.Empty{}), "could not send Health ping") + return s.errs.Wrap(s.health.Send(&sdk.Empty{}), "could not send Health ping") } // SetLabel sets a metadata label on the `GameServer` with the prefix "agones.dev/sdk-". func (s *SDK) SetLabel(key, value string) error { kv := &sdk.KeyValue{Key: key, Value: value} _, err := s.client.SetLabel(s.ctx, kv) - return errors.Wrap(err, "could not set label") + return s.errs.Wrap(err, "could not set label") } // SetAnnotation sets a metadata annotation on the `GameServer` with the prefix "agones.dev/sdk-". func (s *SDK) SetAnnotation(key, value string) error { kv := &sdk.KeyValue{Key: key, Value: value} _, err := s.client.SetAnnotation(s.ctx, kv) - return errors.Wrap(err, "could not set annotation") + return s.errs.Wrap(err, "could not set annotation") } // GameServer retrieve the GameServer details. func (s *SDK) GameServer() (*sdk.GameServer, error) { gs, err := s.client.GetGameServer(s.ctx, &sdk.Empty{}) - return gs, errors.Wrap(err, "could not retrieve gameserver") + return gs, s.errs.Wrap(err, "could not retrieve gameserver") } // WatchGameServer asynchronously calls the given GameServerCallback with the current GameServer @@ -151,7 +153,7 @@ func (s *SDK) GameServer() (*sdk.GameServer, error) { func (s *SDK) WatchGameServer(f GameServerCallback) error { stream, err := s.client.WatchGameServer(s.ctx, &sdk.Empty{}) if err != nil { - return errors.Wrap(err, "could not watch gameserver") + return s.errs.Wrap(err, "could not watch gameserver") } log := func(gs *sdk.GameServer, msg string, err error) { if gs == nil || gs.ObjectMeta.DeletionTimestamp == 0 { @@ -164,7 +166,7 @@ func (s *SDK) WatchGameServer(f GameServerCallback) error { var gs *sdk.GameServer gs, err = stream.Recv() if err != nil { - if errors.Is(err, io.EOF) { + if stderrors.Is(err, io.EOF) { log(gs, "gameserver event stream EOF received", nil) return } diff --git a/test/e2e/gameserver_test.go b/test/e2e/gameserver_test.go index 122e3db988..73c61cb44e 100644 --- a/test/e2e/gameserver_test.go +++ b/test/e2e/gameserver_test.go @@ -1655,19 +1655,19 @@ func TestCounters(t *testing.T) { }, "IncrementCounter Past Capacity": { msg: "INCREMENT_COUNTER games 50", - want: "ERROR: could not increment Counter games by amount 50: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: 51, Capacity: 50\n", + want: "could not increment Counter games by amount 50: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: 51, Capacity: 50\n", counterName: "games", wantCount: "COUNTER: 1\n", }, "IncrementCounter Negative": { msg: "INCREMENT_COUNTER games -1", - want: "ERROR: amount must be a positive int64, found -1\n", + want: "amount must be a positive int64, found -1\n", counterName: "games", wantCount: "COUNTER: 1\n", }, "IncrementCounter Counter Does Not Exist": { msg: "INCREMENT_COUNTER same 1", - want: "ERROR: could not increment Counter same by amount 1: rpc error: code = Unknown desc = counter not found: same\n", + want: "could not increment Counter same by amount 1: rpc error: code = Unknown desc = counter not found: same\n", }, "DecrementCounter": { msg: "DECREMENT_COUNTER bar 10", @@ -1677,19 +1677,19 @@ func TestCounters(t *testing.T) { }, "DecrementCounter Past Capacity": { msg: "DECREMENT_COUNTER games 2", - want: "ERROR: could not decrement Counter games by amount 2: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: -1, Capacity: 50\n", + want: "could not decrement Counter games by amount 2: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: -1, Capacity: 50\n", counterName: "games", wantCount: "COUNTER: 1\n", }, "DecrementCounter Negative": { msg: "DECREMENT_COUNTER games -1", - want: "ERROR: amount must be a positive int64, found -1\n", + want: "amount must be a positive int64, found -1\n", counterName: "games", wantCount: "COUNTER: 1\n", }, "DecrementCounter Counter Does Not Exist": { msg: "DECREMENT_COUNTER lame 1", - want: "ERROR: could not decrement Counter lame by amount 1: rpc error: code = Unknown desc = counter not found: lame\n", + want: "could not decrement Counter lame by amount 1: rpc error: code = Unknown desc = counter not found: lame\n", }, "SetCounterCount": { msg: "SET_COUNTER_COUNT baz 0", @@ -1699,13 +1699,13 @@ func TestCounters(t *testing.T) { }, "SetCounterCount Past Capacity": { msg: "SET_COUNTER_COUNT games 51", - want: "ERROR: could not set Counter games count to amount 51: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: 51, Capacity: 50\n", + want: "could not set Counter games count to amount 51: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: 51, Capacity: 50\n", counterName: "games", wantCount: "COUNTER: 1\n", }, "SetCounterCount Past Zero": { msg: "SET_COUNTER_COUNT games -1", - want: "ERROR: could not set Counter games count to amount -1: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: -1, Capacity: 50\n", + want: "could not set Counter games count to amount -1: rpc error: code = Unknown desc = out of range. Count must be within range [0,Capacity]. Found Count: -1, Capacity: 50\n", counterName: "games", wantCount: "COUNTER: 1\n", }, @@ -1725,7 +1725,7 @@ func TestCounters(t *testing.T) { }, "SetCounterCapacity Past Zero": { msg: "SET_COUNTER_CAPACITY games -42", - want: "ERROR: could not set Counter games capacity to amount -42: rpc error: code = Unknown desc = out of range. Capacity must be greater than or equal to 0. Found Capacity: -42\n", + want: "could not set Counter games capacity to amount -42: rpc error: code = Unknown desc = out of range. Capacity must be greater than or equal to 0. Found Capacity: -42\n", counterName: "games", wantCount: "COUNTER: 1\n", }, @@ -1748,7 +1748,11 @@ func TestCounters(t *testing.T) { logrus.WithField("msg", testCase.msg).Info(name) reply, err := framework.SendGameServerUDP(t, gs, testCase.msg) require.NoError(t, err) - assert.Equal(t, testCase.want, reply) + if strings.HasPrefix(reply, "ERROR: ") { + assert.Contains(t, reply, testCase.want) + } else { + assert.Equal(t, testCase.want, reply) + } if testCase.wantCount != "" { msg := "GET_COUNTER_COUNT " + testCase.counterName @@ -1795,13 +1799,13 @@ func TestLists(t *testing.T) { }, "SetListCapacity past 1000": { msg: "SET_LIST_CAPACITY games 1001", - want: "ERROR: could not set List games capacity to amount 1001: rpc error: code = Unknown desc = out of range. Capacity must be within range [0,1000]. Found Capacity: 1001\n", + want: "could not set List games capacity to amount 1001: rpc error: code = Unknown desc = out of range. Capacity must be within range [0,1000]. Found Capacity: 1001\n", listName: "games", wantCapacity: "CAPACITY: 50\n", }, "SetListCapacity negative": { msg: "SET_LIST_CAPACITY games -1", - want: "ERROR: could not set List games capacity to amount -1: rpc error: code = Unknown desc = out of range. Capacity must be within range [0,1000]. Found Capacity: -1\n", + want: "could not set List games capacity to amount -1: rpc error: code = Unknown desc = out of range. Capacity must be within range [0,1000]. Found Capacity: -1\n", listName: "games", wantCapacity: "CAPACITY: 50\n", }, @@ -1833,7 +1837,7 @@ func TestLists(t *testing.T) { }, "AppendListValue past capacity": { msg: "APPEND_LIST_VALUE baz baz2", - want: "ERROR: could not get List baz: rpc error: code = Unknown desc = out of range. No available capacity. Current Capacity: 1, List Size: 1\n", + want: "could not get List baz: rpc error: code = Unknown desc = out of range. No available capacity. Current Capacity: 1, List Size: 1\n", listName: "baz", wantLength: "LENGTH: 1\n", }, @@ -1845,7 +1849,7 @@ func TestLists(t *testing.T) { }, "DeleteListValue value does not exist": { msg: "DELETE_LIST_VALUE games game4", - want: "ERROR: could not get List games: rpc error: code = Unknown desc = not found: value game4 not in list games\n", + want: "could not get List games: rpc error: code = Unknown desc = not found: value game4 not in list games\n", listName: "games", wantLength: "LENGTH: 2\n", }, @@ -1870,7 +1874,11 @@ func TestLists(t *testing.T) { logrus.WithField("msg", testCase.msg).Info(name) reply, err := framework.SendGameServerUDP(t, gs, testCase.msg) require.NoError(t, err) - assert.Equal(t, testCase.want, reply) + if strings.HasPrefix(reply, "ERROR: ") { + assert.Contains(t, reply, testCase.want) + } else { + assert.Equal(t, testCase.want, reply) + } if testCase.wantLength != "" { msg := "GET_LIST_LENGTH " + testCase.listName