forked from buildpacks/lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
42 lines (35 loc) · 1.09 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package lifecycle_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpacks/lifecycle"
)
func TestUtils(t *testing.T) {
spec.Run(t, "Utils", testUtils, spec.Report(report.Terminal{}))
}
func testUtils(t *testing.T, when spec.G, it spec.S) {
when(".TruncateSha", func() {
it("should truncate the sha", func() {
actual := lifecycle.TruncateSha("ed649d0a36b218c476b64d61f85027477ef5742045799f45c8c353562279065a")
if s := cmp.Diff(actual, "ed649d0a36b2"); s != "" {
t.Fatalf("Unexpected sha:\n%s\n", s)
}
})
it("should not truncate the sha with it's short", func() {
sha := "not-a-sha"
actual := lifecycle.TruncateSha(sha)
if s := cmp.Diff(actual, sha); s != "" {
t.Fatalf("Unexpected sha:\n%s\n", s)
}
})
it("should remove the prefix", func() {
sha := "sha256:ed649d0a36b218c476b64d61f85027477ef5742045799f45c8c353562279065a"
actual := lifecycle.TruncateSha(sha)
if s := cmp.Diff(actual, "ed649d0a36b2"); s != "" {
t.Fatalf("Unexpected sha:\n%s\n", s)
}
})
})
}