|
| 1 | +// Copyright 2023 The Operator-SDK Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package fbcutil |
| 16 | + |
| 17 | +import ( |
| 18 | + "crypto/sha256" |
| 19 | + "fmt" |
| 20 | + "testing" |
| 21 | + |
| 22 | + . "github.com/onsi/ginkgo/v2" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | +) |
| 25 | + |
| 26 | +var _ = Describe("test fbutil", func() { |
| 27 | + |
| 28 | + emptyListHash := fmt.Sprintf("%x", sha256.New().Sum(nil)) |
| 29 | + |
| 30 | + Context("test dirNameFromRefs", func() { |
| 31 | + DescribeTable("should name the directory with sha256 of the concatenation of the bundle image names", func(refs []string, expectedHash string) { |
| 32 | + dirName := dirNameFromRefs(refs) |
| 33 | + |
| 34 | + Expect(dirName).Should(HaveLen(sha256.Size * 2)) // in hex representation, each byte is two hex digits |
| 35 | + Expect(dirName).Should(Equal(expectedHash)) |
| 36 | + }, |
| 37 | + Entry("long image names", []string{ |
| 38 | + "BtU5KRr8IWafnGTvckShoj3xBb5duLZp/XKHZRpOqdVxhHQkCL0Dy0lSRw0a0M/y158JRQKk1S@6KAauQHujQ30my9sivVYGZahR7R7UUSoUBUmnuFdqGHiUTT0aV5Di2", |
| 39 | + "lKM63iKupQcUPKd6AAsmRRABbGYNmwFTmQEX6fpswndQdb/niJPLRG8WhzaH84Q3kfZC/7hc3nK7Oeq@L5KxmVqbAz6jXlv1yKna2cH4zbZ3be0pcYNHyCSVUG/ZVqRAo", |
| 40 | + }, "cc048355dce06491fd090ce0c3ce5a48db3528250ad13a4fbf4090a3de8c325a"), |
| 41 | + Entry("multiple refs", []string{"a/b/c", "d/e/f", "g/h/i/j", "k/l/m/n/o"}, "df22ac3ac9e59ed300f70b9c2fdd7128be064652839a813948ee9fd1a2f36581"), |
| 42 | + Entry("single ref", []string{"a/b/c"}, "cbd2be7b96f770a0326948ebd158cf539fab0627e8adbddc97f7a65c6a8ae59a"), |
| 43 | + Entry("no refs", []string{}, emptyListHash), |
| 44 | + Entry("no refs (nil)", nil, emptyListHash), |
| 45 | + ) |
| 46 | + }) |
| 47 | +}) |
| 48 | + |
| 49 | +func TestRegistry(t *testing.T) { |
| 50 | + RegisterFailHandler(Fail) |
| 51 | + RunSpecs(t, "fbutil Suite") |
| 52 | +} |
0 commit comments