Skip to content

Commit

Permalink
Switch digest to contentDigest in the json tags (#75)
Browse files Browse the repository at this point in the history
* Switch `digest` to `contentDigest` in the json tags

This PR swaps `contentDigest` in place of `digest` in the json/mapstructure tags for the BaseImage type. Adds a test for marashalling as well.

Fixes #59

* Updated code review comments
  • Loading branch information
jeremyrickard authored and glyn committed Jul 24, 2019
1 parent b00ad0a commit 098f359
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type LocationRef struct {
type BaseImage struct {
ImageType string `json:"imageType" mapstructure:"imageType"`
Image string `json:"image" mapstructure:"image"`
Digest string `json:"digest,omitempty" mapstructure:"digest"`
Digest string `json:"contentDigest,omitempty" mapstructure:"contentDigest"`
Size uint64 `json:"size,omitempty" mapstructure:"size"`
Labels map[string]string `json:"labels,omitempty" mapstructure:"labels"`
MediaType string `json:"mediaType,omitempty" mapstructure:"mediaType"`
Expand Down
22 changes: 22 additions & 0 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,25 @@ func TestBundle_RoundTrip(t *testing.T) {
})
}
}

func TestDigestPresent(t *testing.T) {
bun, err := ioutil.ReadFile("../testdata/bundles/digest.json")
require.NoError(t, err, "couldn't read test bundle")

bundle, err := Unmarshal(bun)
require.NoError(t, err, "the bundle should have been valid")

require.Equal(t, 1, len(bundle.InvocationImages), "there should be one invocation image in the bundle")
assert.Equal(t,
"sha256:decafbad71b4175951f29eb96035604c8cc372c99affa2e6d05cde6e8e20cc9a",
bundle.InvocationImages[0].Digest,
)

image, ok := bundle.Images["my-microservice"]
require.True(t, ok, "there should been an image named my-microservice in the bundle")
assert.Equal(
t,
"sha256:beefcacef6c04336a17761db2004813982abe0e87ab727a376c291e09391ea61",
image.Digest,
)
}
67 changes: 67 additions & 0 deletions testdata/bundles/digest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "foo",
"version": "1.0",
"schemaVersion": "99.99",
"images": {
"my-microservice": {
"contentDigest": "sha256:beefcacef6c04336a17761db2004813982abe0e87ab727a376c291e09391ea61",
"description": "my microservice",
"image": "technosophos/microservice:1.2.3"
}
},
"invocationImages": [
{
"contentDigest": "sha256:decafbad71b4175951f29eb96035604c8cc372c99affa2e6d05cde6e8e20cc9a",
"image": "technosophos/helloworld:0.1.0",
"imageType": "docker"
}
],
"credentials": {
"foo": {
"path": "pfoo"
},
"bar": {
"env": "ebar"
},
"quux": {
"path": "pquux",
"env": "equux"
}
},
"custom": {
"com.example.duffle-bag": {
"icon": "https://example.com/icon.png",
"iconType": "PNG"
},
"com.example.backup-preferences": {
"enabled": true,
"frequency": "daily"
}
},
"definitions" : {
"complexThing" : {
"type" : "object",
"properties" : {
"host" : {
"default" : "localhost",
"type" : "string",
"minLength" : 3,
"maxLength" : 10
},
"port" : {
"type" : "integer",
"minimum": 8000
}
},
"required" : ["port"]
}
},
"parameters" : {
"serverConfig" : {
"definition" : "complexThing",
"destination" : {
"path": "/cnab/is/go"
}
}
}
}

0 comments on commit 098f359

Please sign in to comment.