Skip to content

Commit

Permalink
Ensure skipPush defaults to false (#439)
Browse files Browse the repository at this point in the history
* Explicitly set skipPush default to

* rename setRegistry to marshalRegistry

* better code through linting
  • Loading branch information
guineveresaenger authored Dec 12, 2022
1 parent 5bc1207 commit 9c69e03
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
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)
})
}

0 comments on commit 9c69e03

Please sign in to comment.