package gamelimits import "testing" // TestLimitsCap checks Cap maps each kind to its field and leaves the unknown kind uncapped, so a // untagged game (game_kind 0) is never gated. func TestLimitsCap(t *testing.T) { l := Limits{VsAI: 1, Random: 2, Friends: 3} for _, tc := range []struct { kind Kind want int }{ {KindVsAI, 1}, {KindRandom, 2}, {KindFriends, 3}, {KindUnknown, Unlimited}, {Kind(99), Unlimited}, } { if got := l.Cap(tc.kind); got != tc.want { t.Errorf("Cap(%d) = %d, want %d", tc.kind, got, tc.want) } } } // TestServiceLimitsForTier checks LimitsFor selects the guest or durable tier from the cached config. func TestServiceLimitsForTier(t *testing.T) { svc := NewService(nil) svc.set(Config{ Guest: Limits{VsAI: 1, Random: 1, Friends: 0}, Durable: Limits{VsAI: 10, Random: 10, Friends: 10}, }) if got := svc.LimitsFor(true); got != (Limits{VsAI: 1, Random: 1, Friends: 0}) { t.Errorf("guest limits = %+v, want {1 1 0}", got) } if got := svc.LimitsFor(false); got != (Limits{VsAI: 10, Random: 10, Friends: 10}) { t.Errorf("durable limits = %+v, want {10 10 10}", got) } // The unlimited sentinel resolves through the tier too. svc.set(Config{Durable: Limits{VsAI: Unlimited, Random: Unlimited, Friends: Unlimited}}) if got := svc.LimitsFor(false).Cap(KindVsAI); got != Unlimited { t.Errorf("durable vs_ai cap = %d, want unlimited (-1)", got) } }