Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed May 14, 2024
1 parent c077738 commit d612022
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/verifiers/sha256_asset_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ var _ = Describe("Sha256AssetVerifier", func() {
Expect(newVerifier).ShouldNot(BeNil())
})
})

It("should return the correct asset", func() {
Expect(verifier.GetAsset()).To(Equal(&asset))
})
})
8 changes: 8 additions & 0 deletions lib/verifiers/sha256_sum_file_asset_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ var _ = Describe("Sha256SumFileAssetVerifier", func() {
})
})
})

It("should return a string representation of the verifier", func() {
Expect(verifier.String()).To(Equal("checksum verified with https://example.com/sha256sums.txt"))
})

It("should return the correct asset", func() {
Expect(verifier.GetAsset()).To(Equal(asset))
})
})
1 change: 1 addition & 0 deletions lib/verifiers/sha256_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewSha256Verifier(client download.ClientContract, expectedHex string) (*Sha
return &Sha256Verifier{
client: client,
Expected: expected,
Asset: nil,
}, nil
}

Expand Down
16 changes: 16 additions & 0 deletions lib/verifiers/sha256_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ var _ = Describe("Sha256Verifier", func() {
Expect(err).ToNot(BeNil())
})
})

It("should return a string representation of the verifier", func() {
expectedHex := sha256.Sum256([]byte("test"))
hexString := hex.EncodeToString(expectedHex[:])
v, _ := verifiers.NewSha256Verifier(mockClient, hexString)

Expect(v.String()).To(Equal("sha256:" + hexString))
})

It("should return the correct asset", func() {
expectedHex := sha256.Sum256([]byte("test"))
hexString := hex.EncodeToString(expectedHex[:])
v, _ := verifiers.NewSha256Verifier(mockClient, hexString)

Expect(v.GetAsset()).To(BeNil())
})
})

0 comments on commit d612022

Please sign in to comment.