Skip to content

Commit

Permalink
Merge pull request #2253 from balopat/add_one_more_local_test
Browse files Browse the repository at this point in the history
another testcase for local builder
  • Loading branch information
balopat authored Jun 13, 2019
2 parents f462c0b + 6d522df commit 3f0dab6
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions pkg/skaffold/build/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ type dummyLocalDaemon struct {
func TestNewBuilder(t *testing.T) {
dummyDaemon := dummyLocalDaemon{}

pFalse := false

tcs := []struct {
name string
shouldErr bool
localBuild *latest.LocalBuild
expectedBuilder *Builder
localClusterFn func() (bool, error)
localDockerFn func(*runcontext.RunContext) (docker.LocalDaemon, error)
Expand All @@ -278,16 +281,44 @@ func TestNewBuilder(t *testing.T) {
return
},
localClusterFn: func() (b bool, e error) {
b = false
b = false //because this is false and localBuild.push is nil
return
},

shouldErr: false,
expectedBuilder: &Builder{
cfg: &latest.LocalBuild{},
kubeContext: "",
localDocker: dummyDaemon,
localCluster: false,
pushImages: true,
pushImages: true, //this will be true
skipTests: false,
prune: true,
insecureRegistries: nil,
},
}, {
name: "pushImages defined in config (local:push)",
localDockerFn: func(runContext *runcontext.RunContext) (daemon docker.LocalDaemon, e error) {
daemon = dummyDaemon
return
},
localClusterFn: func() (b bool, e error) {
b = false
return
},
localBuild: &latest.LocalBuild{
Push: &pFalse, //because this is false
},
shouldErr: false,
expectedBuilder: &Builder{
pushImages: false, //this will be false too
cfg: &latest.LocalBuild{ // and the config is inherited
Push: &pFalse,
},
kubeContext: "",
localDocker: dummyDaemon,
localCluster: false,

skipTests: false,
prune: true,
insecureRegistries: nil,
Expand All @@ -302,7 +333,7 @@ func TestNewBuilder(t *testing.T) {
if tc.localClusterFn != nil {
t.Override(&getLocalCluster, tc.localClusterFn)
}
builder, err := NewBuilder(dummyRunContext())
builder, err := NewBuilder(stubRunContext(tc.localBuild))
t.CheckError(tc.shouldErr, err)
if !tc.shouldErr {
t.CheckDeepEqual(tc.expectedBuilder, builder, cmp.AllowUnexported(Builder{}, dummyDaemon))
Expand All @@ -311,12 +342,15 @@ func TestNewBuilder(t *testing.T) {
}
}

func dummyRunContext() *runcontext.RunContext {
func stubRunContext(localBuild *latest.LocalBuild) *runcontext.RunContext {
if localBuild == nil {
localBuild = &latest.LocalBuild{}
}
return &runcontext.RunContext{
Cfg: &latest.Pipeline{
Build: latest.BuildConfig{
BuildType: latest.BuildType{
LocalBuild: &latest.LocalBuild{},
LocalBuild: localBuild,
},
},
},
Expand Down

0 comments on commit 3f0dab6

Please sign in to comment.