Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

another testcase for local builder #2253

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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