(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 62 | func TestPRFindRefs(t *testing.T) { |
| 63 | t.Parallel() |
nothing calls this directly
no test coverage detected