@@ -45,51 +45,32 @@ func TestResolveTag(t *testing.T) {
45
45
repository , err := git .PlainInit (repositoryPath .String (), false )
46
46
require .Nil (t , err )
47
47
48
- testTables := []struct {
49
- objectTypeName string
50
- objectHash plumbing.Hash
51
- annotated bool
52
- errorAssertion assert.ErrorAssertionFunc
48
+ commitHash := makeCommit (t , repository , repositoryPath )
49
+ treeHash := getTreeHash (t , repository )
50
+ blobHash := getBlobHash (t , repository )
51
+ testTable := []struct {
52
+ name string
53
+ hash plumbing.Hash
54
+ annotated bool
55
+ assertion assert.ErrorAssertionFunc
53
56
}{
54
- {
55
- objectTypeName : "Commit" ,
56
- objectHash : makeCommit (t , repository , repositoryPath ),
57
- errorAssertion : assert .NoError ,
58
- },
59
- {
60
- objectTypeName : "Tree" ,
61
- objectHash : getTreeHash (t , repository ),
62
- errorAssertion : assert .Error ,
63
- },
64
- {
65
- objectTypeName : "Blob" ,
66
- objectHash : getBlobHash (t , repository ),
67
- errorAssertion : assert .Error ,
68
- },
57
+ {name : "Commit" , hash : commitHash , assertion : assert .NoError },
58
+ {name : "Tree" , hash : treeHash , assertion : assert .Error },
59
+ {name : "Blob" , hash : blobHash , assertion : assert .Error },
60
+ {name : "AnnotatedCommit" , hash : commitHash , assertion : assert .NoError , annotated : true },
61
+ {name : "AnnotatedTree" , hash : treeHash , assertion : assert .Error , annotated : true },
62
+ {name : "AnnotatedBlob" , hash : blobHash , assertion : assert .Error , annotated : true },
69
63
}
70
64
71
- for _ , testTable := range testTables {
72
- for _ , annotationConfig := range []struct {
73
- annotated bool
74
- descriptor string
75
- }{
76
- {
77
- annotated : true ,
78
- descriptor : "Annotated" ,
79
- },
80
- {
81
- annotated : false ,
82
- descriptor : "Lightweight" ,
83
- },
84
- } {
85
- testName := fmt .Sprintf ("%s, %s" , testTable .objectTypeName , annotationConfig .descriptor )
86
- tag := makeTag (t , repository , testName , testTable .objectHash , annotationConfig .annotated )
65
+ for _ , test := range testTable {
66
+ t .Run (test .name , func (t * testing.T ) {
67
+ tag := makeTag (t , repository , test .name , test .hash , test .annotated )
87
68
resolvedTag , err := resolveTag (tag , repository )
88
- testTable . errorAssertion (t , err , fmt . Sprintf ( "%s tag resolution error", testName ) )
69
+ test . assertion (t , err , " tag resolution error" )
89
70
if err == nil {
90
- assert .Equal (t , testTable . objectHash , * resolvedTag , fmt . Sprintf ( "%s tag resolution", testName ) )
71
+ assert .Equal (t , test . hash , * resolvedTag , " tag resolution" )
91
72
}
92
- }
73
+ })
93
74
}
94
75
}
95
76
@@ -202,12 +183,12 @@ func makeCommit(t *testing.T, repository *git.Repository, repositoryPath *paths.
202
183
// commitFile commits a file in the given repository and returns its path and the commit's plumbing.Hash object.
203
184
func commitFile (t * testing.T , repository * git.Repository , repositoryPath * paths.Path ) (* paths.Path , plumbing.Hash ) {
204
185
filePath , err := paths .WriteToTempFile ([]byte {}, repositoryPath , "gitutils-makeCommit-tempfile" )
205
- require .Nil (t , err )
186
+ require .NoError (t , err )
206
187
207
188
worktree , err := repository .Worktree ()
208
- require .Nil (t , err )
189
+ require .NoError (t , err )
209
190
_ , err = worktree .Add ("." )
210
- require .Nil (t , err )
191
+ require .NoError (t , err )
211
192
212
193
signature := & object.Signature {
213
194
Name : "Jane Developer" ,
@@ -221,26 +202,26 @@ func commitFile(t *testing.T, repository *git.Repository, repositoryPath *paths.
221
202
Author : signature ,
222
203
},
223
204
)
224
- require .Nil (t , err )
205
+ require .NoError (t , err )
225
206
226
207
return filePath , commit
227
208
}
228
209
229
210
// getTreeHash returns the plumbing.Hash object for an arbitrary Git tree object.
230
211
func getTreeHash (t * testing.T , repository * git.Repository ) plumbing.Hash {
231
212
trees , err := repository .TreeObjects ()
232
- require .Nil (t , err )
213
+ require .NoError (t , err )
233
214
tree , err := trees .Next ()
234
- require .Nil (t , err )
215
+ require .NoError (t , err )
235
216
return tree .ID ()
236
217
}
237
218
238
219
// getTreeHash returns the plumbing.Hash object for an arbitrary Git blob object.
239
220
func getBlobHash (t * testing.T , repository * git.Repository ) plumbing.Hash {
240
221
blobs , err := repository .BlobObjects ()
241
- require .Nil (t , err )
222
+ require .NoError (t , err )
242
223
blob , err := blobs .Next ()
243
- require .Nil (t , err )
224
+ require .NoError (t , err )
244
225
return blob .ID ()
245
226
}
246
227
0 commit comments