Skip to content

Commit

Permalink
Fix slow tests (#4741)
Browse files Browse the repository at this point in the history
Mock docker client

Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot authored Aug 31, 2020
1 parent e4ec899 commit 31d035a
Showing 1 changed file with 50 additions and 41 deletions.
91 changes: 50 additions & 41 deletions pkg/skaffold/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,63 +35,72 @@ 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 })

deps, err := NewTester(runCtx, true).TestDependencies()
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(),
Cfg: latest.Pipeline{
Test: []*latest.TestCase{
{StructureTests: []string{"./tests/*"}},
{},
{StructureTests: []string{"test3.yaml"}},
runCtx := &runcontext.RunContext{
WorkingDir: tmpDir.Root(),
Cfg: latest.Pipeline{
Test: []*latest.TestCase{
{StructureTests: []string{"./tests/*"}},
{},
{StructureTests: []string{"test3.yaml"}},
},
},
},
}

deps, err := NewTester(runCtx, true).TestDependencies()
}
deps, err := NewTester(runCtx, true).TestDependencies()

expectedDeps := tmpDir.Paths("tests/test1.yaml", "tests/test2.yaml", "test3.yaml")
testutil.CheckErrorAndDeepEqual(t, false, err, expectedDeps, deps)
expectedDeps := tmpDir.Paths("tests/test1.yaml", "tests/test2.yaml", "test3.yaml")
t.CheckNoError(err)
t.CheckDeepEqual(expectedDeps, deps)
})
}

func TestWrongPattern(t *testing.T) {
runCtx := &runcontext.RunContext{
Cfg: latest.Pipeline{
Test: []*latest.TestCase{{
ImageName: "image",
StructureTests: []string{"[]"},
}},
},
}

tester := NewTester(runCtx, true)

_, err := tester.TestDependencies()
testutil.CheckError(t, true, err)

err = tester.Test(context.Background(), ioutil.Discard, []build.Artifact{{
ImageName: "image",
Tag: "image:tag",
}})
testutil.CheckError(t, true, err)
testutil.Run(t, "", func(t *testutil.T) {
runCtx := &runcontext.RunContext{
Cfg: latest.Pipeline{
Test: []*latest.TestCase{{
ImageName: "image",
StructureTests: []string{"[]"},
}},
},
}

tester := NewTester(runCtx, true)

_, err := tester.TestDependencies()
t.CheckError(true, err)

err = tester.Test(context.Background(), ioutil.Discard, []build.Artifact{{
ImageName: "image",
Tag: "image:tag",
}})
t.CheckError(true, err)
})
}

func TestNoTest(t *testing.T) {
runCtx := &runcontext.RunContext{}
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) {
Expand Down

0 comments on commit 31d035a

Please sign in to comment.