package runtime

import "testing"

func TestEngineLabels(t *testing.T) {
	t.Parallel()

	cases := []struct {
		name       string
		gameID     string
		version    string
		stackLabel string
		want       map[string]string
	}{
		{
			name:       "stack label omitted when empty",
			gameID:     "11111111-1111-1111-1111-111111111111",
			version:    "0.1.0",
			stackLabel: "",
			want: map[string]string{
				"galaxy.game_id":        "11111111-1111-1111-1111-111111111111",
				"galaxy.engine_version": "0.1.0",
			},
		},
		{
			name:       "stack label included when set",
			gameID:     "22222222-2222-2222-2222-222222222222",
			version:    "0.2.3",
			stackLabel: "dev-deploy",
			want: map[string]string{
				"galaxy.game_id":        "22222222-2222-2222-2222-222222222222",
				"galaxy.engine_version": "0.2.3",
				"galaxy.stack":          "dev-deploy",
			},
		},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			got := engineLabels(tc.gameID, tc.version, tc.stackLabel)
			if len(got) != len(tc.want) {
				t.Fatalf("len(labels) = %d, want %d (got %v)", len(got), len(tc.want), got)
			}
			for k, v := range tc.want {
				if got[k] != v {
					t.Errorf("labels[%q] = %q, want %q", k, got[k], v)
				}
			}
		})
	}
}
