MCPcopy
hub / github.com/github/git-sizer / TestRefSelections

Function TestRefSelections

git_sizer_test.go:103–301  ·  view source on GitHub ↗

TestRefSelections tests various combinations of reference selection options.

(t *testing.T)

Source from the content-addressed store, hash-verified

101// TestRefSelections tests various combinations of reference selection
102// options.
103func TestRefSelections(t *testing.T) {
104 t.Parallel()
105
106 references := []struct {
107 // The plusses and spaces in the `results` string correspond
108 // to the expected results for one of the tests: `results[i]`
109 // tells whether we expect `refname` to be included ('+') or
110 // excluded (' ') in test case number `i`.
111 results string
112
113 refname string
114 }{
115 //nolint:gocritic // Want columns in comment to match initializers.
116 // 111111111
117 //0123456789012345678
118 {"+ + + + + + + + +", "refs/barfoo"},
119 {"+ + + + + + +++ ", "refs/foo"},
120 {"+ + + + + + + + +", "refs/foobar"},
121 {"++ + + + +++ +++", "refs/heads/foo"},
122 {"++ + + + ++ +++", "refs/heads/master"},
123 {"+ + + ++ + ", "refs/notes/discussion"},
124 {"+ + ++ + + ", "refs/remotes/origin/master"},
125 {"+ + ++ + + + + +", "refs/remotes/upstream/foo"},
126 {"+ + ++ + + ", "refs/remotes/upstream/master"},
127 {"+ + + + ++ ", "refs/stash"},
128 {"+ ++ + + +++ + +", "refs/tags/foolish"},
129 {"+ ++ + + ++ + +", "refs/tags/other"},
130 {"+ ++ + + ++ + ", "refs/tags/release-1"},
131 {"+ ++ + + ++ + ", "refs/tags/release-2"},
132 }
133
134 // computeExpectations assembles and returns the results expected
135 // for test `i` from the `references` slice.
136 computeExpectations := func(i int) (string, int) {
137 var sb strings.Builder
138 fmt.Fprintln(&sb, "References (included references marked with '+'):")
139 count := 0
140 for _, p := range references {
141 present := p.results[i]
142 fmt.Fprintf(&sb, "%c %s\n", present, p.refname)
143 if present == '+' {
144 count++
145 }
146 }
147 return sb.String(), count
148 }
149
150 // Create a test repo with one orphan commit per refname:
151 repo := testutils.NewTestRepo(t, true, "ref-selection")
152 t.Cleanup(func() { repo.Remove(t) })
153
154 for _, p := range references {
155 repo.CreateReferencedOrphan(t, p.refname)
156 }
157
158 executable := sizerExe(t)
159
160 for i, p := range []struct {

Callers

nothing calls this directly

Calls 9

RemoveMethod · 0.95
CloneMethod · 0.95
ConfigAddMethod · 0.95
NewTestRepoFunction · 0.92
sizerExeFunction · 0.85
RunMethod · 0.80
BytesMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected