MCPcopy
hub / github.com/cli/cli / TestQualifiedHeadRef

Function TestQualifiedHeadRef

pkg/cmd/pr/shared/find_refs_resolution_test.go:16–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestQualifiedHeadRef(t *testing.T) {
17 t.Parallel()
18
19 testCases := []struct {
20 behavior string
21 ref string
22 expectedString string
23 expectedBranchName string
24 expectedError error
25 }{
26 {
27 behavior: "when a branch is provided, the parsed qualified head ref only has a branch",
28 ref: "feature-branch",
29 expectedString: "feature-branch",
30 expectedBranchName: "feature-branch",
31 },
32 {
33 behavior: "when an owner and branch are provided, the parsed qualified head ref has both",
34 ref: "owner:feature-branch",
35 expectedString: "owner:feature-branch",
36 expectedBranchName: "feature-branch",
37 },
38 {
39 behavior: "when the structure cannot be interpreted correctly, an error is returned",
40 ref: "owner:feature-branch:extra",
41 expectedError: errors.New("invalid qualified head ref format 'owner:feature-branch:extra'"),
42 },
43 }
44
45 for _, tc := range testCases {
46 t.Run(tc.behavior, func(t *testing.T) {
47 t.Parallel()
48
49 qualifiedHeadRef, err := ParseQualifiedHeadRef(tc.ref)
50 if tc.expectedError != nil {
51 require.Equal(t, tc.expectedError, err)
52 return
53 }
54
55 require.NoError(t, err)
56 assert.Equal(t, tc.expectedString, qualifiedHeadRef.String())
57 assert.Equal(t, tc.expectedBranchName, qualifiedHeadRef.BranchName())
58 })
59 }
60}
61
62func TestPRFindRefs(t *testing.T) {
63 t.Parallel()

Callers

nothing calls this directly

Calls 5

ParseQualifiedHeadRefFunction · 0.85
EqualMethod · 0.80
BranchNameMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected