Go · 1317 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package concurrency_test
4
5 import (
6 "strings"
7 "testing"
8
9 "github.com/tenseleyFlow/shithub/internal/actions/concurrency"
10 )
11
12 func TestResolveGroup_EvaluatesTriggerContext(t *testing.T) {
13 t.Parallel()
14 got, err := concurrency.ResolveGroup("branch-${{ shithub.ref }}-${{ shithub.event.head_commit.id }}", concurrency.EvalContext{
15 EventPayload: map[string]any{
16 "head_commit": map[string]any{"id": "abc123"},
17 },
18 HeadSHA: "abc123",
19 HeadRef: "refs/heads/trunk",
20 })
21 if err != nil {
22 t.Fatalf("ResolveGroup: %v", err)
23 }
24 want := "branch-refs/heads/trunk-abc123"
25 if got != want {
26 t.Fatalf("group: got %q want %q", got, want)
27 }
28 }
29
30 func TestResolveGroup_GithubAliasAndMissingEventPath(t *testing.T) {
31 t.Parallel()
32 got, err := concurrency.ResolveGroup("${{ github.ref }}-${{ shithub.event.missing }}", concurrency.EvalContext{
33 HeadRef: "refs/heads/main",
34 })
35 if err != nil {
36 t.Fatalf("ResolveGroup: %v", err)
37 }
38 if got != "refs/heads/main-" {
39 t.Fatalf("group: got %q", got)
40 }
41 }
42
43 func TestResolveGroup_RejectsTooLongGroup(t *testing.T) {
44 t.Parallel()
45 _, err := concurrency.ResolveGroup(strings.Repeat("x", concurrency.MaxGroupChars+1), concurrency.EvalContext{})
46 if err == nil {
47 t.Fatal("ResolveGroup returned nil error for oversized group")
48 }
49 }
50