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

Ensure skipPush defaults to false #439

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context,
return "", nil, err
}

reg := setRegistry(inputs["registry"])
reg := marshalRegistry(inputs["registry"])
skipPush := marshalSkipPush(inputs["skipPush"])
// read in values to Image
img := Image{
Name: inputs["imageName"].StringValue(),
SkipPush: inputs["skipPush"].BoolValue(),
SkipPush: skipPush,
Registry: reg,
}

Expand Down Expand Up @@ -296,7 +297,7 @@ func marshalCachedImages(img Image, b resource.PropertyValue) []string {
return cacheImages
}

func setRegistry(r resource.PropertyValue) Registry {
func marshalRegistry(r resource.PropertyValue) Registry {
var reg Registry
if !r.IsNull() {
if !r.ObjectValue()["server"].IsNull() {
Expand Down Expand Up @@ -361,3 +362,11 @@ func marshalBuilder(builder resource.PropertyValue) (types.BuilderVersion, error
return version, errors.Errorf("Invalid Docker Builder version")
}
}

func marshalSkipPush(sp resource.PropertyValue) bool {
if sp.IsNull() {
// defaults to false
return false
}
return sp.BoolValue()
}
30 changes: 27 additions & 3 deletions provider/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSetRegistry(t *testing.T) {
"password": resource.NewStringProperty("supersecret"),
})

actual := setRegistry(input)
actual := marshalRegistry(input)
assert.Equal(t, expected, actual)
})
t.Run("Incomplete Registry sets all available fields", func(t *testing.T) {
Expand All @@ -34,14 +34,14 @@ func TestSetRegistry(t *testing.T) {
"username": resource.NewStringProperty("pulumipus"),
})

actual := setRegistry(input)
actual := marshalRegistry(input)
assert.Equal(t, expected, actual)
})

t.Run("Registry can be nil", func(t *testing.T) {
expected := Registry{}
input := resource.PropertyValue{}
actual := setRegistry(input)
actual := marshalRegistry(input)
assert.Equal(t, expected, actual)
})
}
Expand Down Expand Up @@ -378,3 +378,27 @@ func TestMarshalBuilder(t *testing.T) {
assert.NoError(t, err)
})
}

func TestMarshalSkipPush(t *testing.T) {
t.Run("Test SkipPush defaults to false", func(t *testing.T) {
expected := false
input := resource.NewPropertyValue(nil)
actual := marshalSkipPush(input)
assert.Equal(t, expected, actual)

})
t.Run("Test SkipPush returns true if set to true", func(t *testing.T) {
expected := true
input := resource.NewBoolProperty(true)

actual := marshalSkipPush(input)
assert.Equal(t, expected, actual)
})
t.Run("Test SkipPush returns false if set to false", func(t *testing.T) {
expected := false
input := resource.NewBoolProperty(false)

actual := marshalSkipPush(input)
assert.Equal(t, expected, actual)
})
}