Skip to content

Commit

Permalink
Switch digest to contentDigest in the json tags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jeremyrickard committed Jul 23, 2019
1 parent 1a5d2eb commit 966cda2
Show file tree
Hide file tree
Showing 3 changed files with 87 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
19 changes: 19 additions & 0 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,22 @@ 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")

//invocationImages[] should have exactly 1 value
require.Equal(t, 1, len(bundle.InvocationImages), "there should be one invocation image in the bundle")
//the invocation image digest should equal sha256:aaaaaaa...
assert.Equal(t, "sha256:aaaaaaa...", bundle.InvocationImages[0].Digest)

//images[] should have exactly 1 values
_, ok := bundle.Images["my-microservice"]
require.True(t, ok, "there should been an image named my-microservice in the bundle")
// the image digest should equal sha256:aaaaaaaaaaaa...
assert.Equal(t, "sha256:aaaaaaaaaaaa...", bundle.Images["my-microservice"].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:aaaaaaaaaaaa...",
"description": "my microservice",
"image": "technosophos/microservice:1.2.3"
}
},
"invocationImages": [
{
"contentDigest": "sha256:aaaaaaa...",
"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 966cda2

Please sign in to comment.