Commit fc91c0b8 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Test suite cleanup.

parent 5ba84990
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -72,6 +72,13 @@ var (
var cachedTokenGoogle accessTokenGoogle
var cachedTokenHuawei accessTokenHuawei

func init() {
	// Hint to the JWT encoder that single-string arrays should be marshaled as strings.
	// This ensures that for example `["foo"]` is marshaled as `"foo"`.
	// Note: this is required particularly for Google IAP verification JWT audience fields.
	jwt.MarshalSingleStringAsArray = false
}

// Apple

type ValidateReceiptAppleResponseReceiptInApp struct {
@@ -131,7 +138,7 @@ type ValidateReceiptAppleResponse struct {

// Validate an IAP receipt with Apple. This function will check against both the production and sandbox Apple URLs.
func ValidateReceiptApple(ctx context.Context, httpc *http.Client, receipt, password string) (*ValidateReceiptAppleResponse, []byte, error) {
	resp, raw, err := ValidateReceiptAppleWithUrl(ctx, httpc, AppleReceiptValidationUrlSandbox, receipt, password)
	resp, raw, err := ValidateReceiptAppleWithUrl(ctx, httpc, AppleReceiptValidationUrlProduction, receipt, password)
	if err != nil {
		return nil, nil, err
	}
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ func NewAPIServer(t *testing.T, runtime *Runtime) (*ApiServer, *Pipeline) {
	router := &DummyMessageRouter{}
	tracker := &LocalTracker{}
	pipeline := NewPipeline(logger, cfg, db, protojsonMarshaler, protojsonUnmarshaler, nil, nil, nil, nil, nil, tracker, router, runtime)
	apiServer := StartApiServer(logger, logger, db, protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, tracker, router, metrics, pipeline, runtime)
	apiServer := StartApiServer(logger, logger, db, protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, tracker, router, nil, metrics, pipeline, runtime)
	return apiServer, pipeline
}

+8 −8
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ func TestMatchRegistryAuthoritativeMatchAndJoin(t *testing.T) {
	}
	defer matchRegistry.Stop(0)

	res, err := matchRegistry.CreateMatch(context.Background(), consoleLogger,
	res, err := matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{})
	if err != nil {
		t.Fatal(err)
@@ -147,7 +147,7 @@ func TestMatchRegistryAuthoritativeMatchAndListMatches(t *testing.T) {
	}
	defer matchRegistry.Stop(0)

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
	_, err = matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{
			"label": "label",
		})
@@ -182,7 +182,7 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithTokenizableLabel(t *te
	}
	defer matchRegistry.Stop(0)

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
	_, err = matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{
			"label": "label-part2",
		})
@@ -215,7 +215,7 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQuerying(t *testing.T)
	}
	defer matchRegistry.Stop(0)

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
	_, err = matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{
			"label": `{"skill":60}`,
		})
@@ -249,7 +249,7 @@ func TestMatchRegistryAuthoritativeMatchAndListAllMatchesWithQueryStar(t *testin
	}
	defer matchRegistry.Stop(0)

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
	_, err = matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{
			"label": `{"skill":60}`,
		})
@@ -287,7 +287,7 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingArrays(t *test
	convoID2, _ := uuid.NewV4()
	convoID3, _ := uuid.NewV4()

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
	_, err = matchRegistry.CreateMatch(context.Background(),
		runtimeMatchCreateFunc, "match", map[string]interface{}{
			"label": fmt.Sprintf(`{"convo_ids": ["%s", "%s", "%s"]}`, convoID1, convoID2, convoID3),
		})
@@ -332,7 +332,7 @@ func TestMatchRegistryListMatchesAfterLabelsUpdate(t *testing.T) {
		return rmc, nil
	}

	_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger, matchCreateWrapper, "match", nil)
	_, err = matchRegistry.CreateMatch(context.Background(), matchCreateWrapper, "match", nil)
	if err != nil {
		t.Fatal(err)
	}
@@ -379,7 +379,7 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingAndBoost(t *te

	// create all matches
	for _, matchLabel := range matchLabels {
		_, err = matchRegistry.CreateMatch(context.Background(), consoleLogger,
		_, err = matchRegistry.CreateMatch(context.Background(),
			runtimeMatchCreateFunc, "match", map[string]interface{}{
				"label": matchLabel,
			})
+100 −2
Original line number Diff line number Diff line
@@ -59,6 +59,104 @@ func TestMatchmakerAddOnly(t *testing.T) {
	}
}

func TestMatchmakerAddRemoveRepeated(t *testing.T) {
	consoleLogger := loggerForTest(t)
	matchMaker, cleanup, err := createTestMatchmaker(t, consoleLogger, nil)
	if err != nil {
		t.Fatalf("error creating test matchmaker: %v", err)
	}
	defer cleanup()

	sessionID, _ := uuid.NewV4()
	ticket, err := matchMaker.Add([]*MatchmakerPresence{
		&MatchmakerPresence{
			UserId:    "a",
			SessionId: "a",
			Username:  "a",
			Node:      "a",
			SessionID: sessionID,
		},
	}, sessionID.String(), "", "properties.a1:foo", 2, 2, 1, map[string]string{
		"a1": "bar",
	}, map[string]float64{})
	if err != nil {
		t.Fatalf("error matchmaker add: %v", err)
	}
	if ticket == "" {
		t.Fatal("expected valid ticket")
	}

	if err := matchMaker.RemoveSession(sessionID.String(), ticket); err != nil {
		t.Fatalf("error matchmaker remove: %v", err)
	}

	ticket, err = matchMaker.Add([]*MatchmakerPresence{
		&MatchmakerPresence{
			UserId:    "a",
			SessionId: "a",
			Username:  "a",
			Node:      "a",
			SessionID: sessionID,
		},
	}, sessionID.String(), "", "properties.a1:foo", 2, 2, 1, map[string]string{
		"a1": "bar",
	}, map[string]float64{})
	if err != nil {
		t.Fatalf("error matchmaker add: %v", err)
	}
	if ticket == "" {
		t.Fatal("expected valid ticket")
	}

	if err := matchMaker.RemoveSession(sessionID.String(), ticket); err != nil {
		t.Fatalf("error matchmaker remove: %v", err)
	}

	ticket, err = matchMaker.Add([]*MatchmakerPresence{
		&MatchmakerPresence{
			UserId:    "a",
			SessionId: "a",
			Username:  "a",
			Node:      "a",
			SessionID: sessionID,
		},
	}, sessionID.String(), "", "properties.a1:foo", 2, 2, 1, map[string]string{
		"a1": "bar",
	}, map[string]float64{})
	if err != nil {
		t.Fatalf("error matchmaker add: %v", err)
	}
	if ticket == "" {
		t.Fatal("expected valid ticket")
	}

	if err := matchMaker.RemoveSession(sessionID.String(), ticket); err != nil {
		t.Fatalf("error matchmaker remove: %v", err)
	}

	ticket, err = matchMaker.Add([]*MatchmakerPresence{
		&MatchmakerPresence{
			UserId:    "a",
			SessionId: "a",
			Username:  "a",
			Node:      "a",
			SessionID: sessionID,
		},
	}, sessionID.String(), "", "properties.a1:foo", 2, 2, 1, map[string]string{
		"a1": "bar",
	}, map[string]float64{})
	if err != nil {
		t.Fatalf("error matchmaker add: %v", err)
	}
	if ticket == "" {
		t.Fatal("expected valid ticket")
	}

	if err := matchMaker.RemoveSession(sessionID.String(), ticket); err != nil {
		t.Fatalf("error matchmaker remove: %v", err)
	}
}

func TestMatchmakerPropertyRegexSubmatch(t *testing.T) {
	consoleLogger := loggerForTest(t)
	matchMaker, cleanup, err := createTestMatchmaker(t, consoleLogger, nil)
@@ -1545,7 +1643,7 @@ func createTestMatchmaker(t fatalable, logger *zap.Logger,
	}

	runtime, _, err := NewRuntime(context.Background(), logger, logger, nil, jsonpbMarshaler, jsonpbUnmarshaler, cfg,
		nil, nil, nil, nil, sessionRegistry, nil,
		nil, nil, nil, nil, sessionRegistry, nil, nil,
		nil, tracker, metrics, nil, messageRouter)
	if err != nil {
		t.Fatal(err)
@@ -1565,7 +1663,7 @@ func createTestMatchmaker(t fatalable, logger *zap.Logger,
			return "", false, nil
		}

		res, err := matchRegistry.CreateMatch(context.Background(), logger,
		res, err := matchRegistry.CreateMatch(context.Background(),
			runtimeMatchCreateFunc, "match", map[string]interface{}{})
		if err != nil {
			t.Fatal(err)
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ func runtimeWithModules(t *testing.T, modules map[string]string) (*Runtime, *Run
	cfg := NewConfig(logger)
	cfg.Runtime.Path = dir

	return NewRuntime(context.Background(), logger, logger, NewDB(t), protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, metrics, nil, &DummyMessageRouter{})
	return NewRuntime(context.Background(), logger, logger, NewDB(t), protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, metrics, nil, &DummyMessageRouter{})
}

func TestRuntimeSampleScript(t *testing.T) {
@@ -354,7 +354,7 @@ nakama.register_rpc(test.printWorld, "helloworld")`,

	db := NewDB(t)
	pipeline := NewPipeline(logger, cfg, db, protojsonMarshaler, protojsonUnmarshaler, nil, nil, nil, nil, nil, nil, nil, runtime)
	apiServer := StartApiServer(logger, logger, db, protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, metrics, pipeline, runtime)
	apiServer := StartApiServer(logger, logger, db, protojsonMarshaler, protojsonUnmarshaler, cfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, metrics, pipeline, runtime)
	defer apiServer.Stop()

	payload := "\"Hello World\""