Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Use testing.T.Run(...) to run subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
squaremo committed Jun 12, 2018
1 parent f5253eb commit e9a95a3
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,16 @@ func Test_FilterLogic(t *testing.T) {
},
},
} {
checkout, cleanup := setup(t)
defer cleanup()
testRelease(t, tst.Name, &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
registry: mockRegistry,
repo: checkout,
}, tst.Spec, tst.Expected)
t.Run(tst.Name, func(t *testing.T) {
checkout, cleanup := setup(t)
defer cleanup()
testRelease(t, &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
registry: mockRegistry,
repo: checkout,
}, tst.Spec, tst.Expected)
})
}
}

Expand Down Expand Up @@ -413,27 +415,29 @@ func Test_ImageStatus(t *testing.T) {
},
},
} {
checkout, cleanup := setup(t)
defer cleanup()
ctx := &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
repo: checkout,
registry: upToDateRegistry,
}
testRelease(t, tst.Name, ctx, tst.Spec, tst.Expected)
t.Run(tst.Name, func(t *testing.T) {
checkout, cleanup := setup(t)
defer cleanup()
ctx := &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
repo: checkout,
registry: upToDateRegistry,
}
testRelease(t, ctx, tst.Spec, tst.Expected)
})
}
}

func testRelease(t *testing.T, name string, ctx *ReleaseContext, spec update.ReleaseSpec, expected update.Result) {
func testRelease(t *testing.T, ctx *ReleaseContext, spec update.ReleaseSpec, expected update.Result) {
results, err := Release(ctx, spec, log.NewNopLogger())
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, results) {
exp, _ := json.Marshal(expected)
got, _ := json.Marshal(results)
t.Errorf("%s\n--- expected ---\n%s\n--- got ---\n%s\n", name, string(exp), string(got))
t.Errorf("--- expected ---\n%s\n--- got ---\n%s\n", string(exp), string(got))
}
}

Expand Down

0 comments on commit e9a95a3

Please sign in to comment.