Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Jul 25, 2021
1 parent 0256d07 commit 8e3a5c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/actions/mocks/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func CreateMockContainer(id string, name string, image string, created time.Time

// CreateMockContainerWithImageInfo should only be used for testing
func CreateMockContainerWithImageInfo(id string, name string, image string, created time.Time, imageInfo types.ImageInspect) container.Container {
return CreateMockContainerWithImageInfoP(id, name, image, created, &imageInfo)
}

// CreateMockContainerWithImageInfoP should only be used for testing
func CreateMockContainerWithImageInfoP(id string, name string, image string, created time.Time, imageInfo *types.ImageInspect) container.Container {
content := types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: id,
Expand All @@ -57,7 +62,7 @@ func CreateMockContainerWithImageInfo(id string, name string, image string, crea
}
return *container.NewContainer(
&content,
&imageInfo,
imageInfo,
)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/registry/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var _ = Describe("Digests", func() {
mockCreated,
mockDigest)

mockContainerNoImage := mocks.CreateMockContainerWithImageInfoP(mockId, mockName, mockImage, mockCreated, nil)

When("a digest comparison is done", func() {
It("should return true if digests match",
SkipIfCredentialsEmpty(GHCRCredentials, func() {
Expand All @@ -75,6 +77,12 @@ var _ = Describe("Digests", func() {
It("should return an error if the registry isn't available", func() {

})
It("should return an error when container contains no image info", func() {
creds := fmt.Sprintf("%s:%s", GHCRCredentials.Username, GHCRCredentials.Password)
matches, err := digest.CompareDigest(mockContainerNoImage, creds)
Expect(err).To(HaveOccurred())
Expect(matches).To(Equal(false))
})
})
When("using different registries", func() {
It("should work with DockerHub",
Expand Down

0 comments on commit 8e3a5c6

Please sign in to comment.