Fix slow tests
Mock docker client
@@ -35,17 +35,20 @@ import (
)
func TestNoTestDependencies(t *testing.T) {
- runCtx := &runcontext.RunContext{}
+ testutil.Run(t, "", func(t *testutil.T) {
+ t.Override(&docker.NewAPIClient, func(*runcontext.RunContext) (docker.LocalDaemon, error) { return nil, nil })
+ runCtx := &runcontext.RunContext{}
deps, err := NewTester(runCtx, true).TestDependencies()
- testutil.CheckErrorAndDeepEqual(t, false, err, 0, len(deps))
+ t.CheckNoError(err)
+ t.CheckEmpty(deps)
+ })
}
func TestTestDependencies(t *testing.T) {
- tmpDir := testutil.NewTempDir(t)
-
- tmpDir.Touch("tests/test1.yaml", "tests/test2.yaml", "test3.yaml")
+ testutil.Run(t, "", func(t *testutil.T) {
+ tmpDir := t.NewTempDir().Touch("tests/test1.yaml", "tests/test2.yaml", "test3.yaml")
runCtx := &runcontext.RunContext{
WorkingDir: tmpDir.Root(),
@@ -57,14 +60,16 @@ func TestTestDependencies(t *testing.T) {
},
},
}
-
deps, err := NewTester(runCtx, true).TestDependencies()
expectedDeps := tmpDir.Paths("tests/test1.yaml", "tests/test2.yaml", "test3.yaml")
- testutil.CheckErrorAndDeepEqual(t, false, err, expectedDeps, deps)
+ t.CheckNoError(err)
+ t.CheckDeepEqual(expectedDeps, deps)
+ })
}
func TestWrongPattern(t *testing.T) {
+ testutil.Run(t, "", func(t *testutil.T) {
runCtx := &runcontext.RunContext{
Cfg: latest.Pipeline{
Test: []*latest.TestCase{{
@@ -77,21 +82,25 @@ func TestWrongPattern(t *testing.T) {
tester := NewTester(runCtx, true)
_, err := tester.TestDependencies()
- testutil.CheckError(t, true, err)
+ t.CheckError(true, err)
err = tester.Test(context.Background(), ioutil.Discard, []build.Artifact{{
ImageName: "image",
Tag: "image:tag",
}})
- testutil.CheckError(t, true, err)
+ t.CheckError(true, err)
+ })
}
func TestNoTest(t *testing.T) {
+ testutil.Run(t, "", func(t *testutil.T) {
runCtx := &runcontext.RunContext{}
- err := NewTester(runCtx, true).Test(context.Background(), ioutil.Discard, nil)
+ tester := NewTester(runCtx, true)
+ err := tester.Test(context.Background(), ioutil.Discard, nil)
- testutil.CheckError(t, false, err)
+ t.CheckNoError(err)
+ })
}
func TestIgnoreDockerNotFound(t *testing.T) {
