| 1 | // Copyright 2016 CNI 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 utilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 19 | "stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/" |
| 20 | |
| 21 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 22 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 23 | ) |
| 24 | |
| 25 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Utils", func() { |
| 26 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("FormatChainName", func() { |
| 27 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must format a short name", func() { |
| 28 | chain := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("test", "1234") |
| 29 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 30 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-2bbe0c48b91a7d1b8a6753a8")) |
| 31 | }) |
| 32 | |
| 33 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must truncate a long name", func() { |
| 34 | chain := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("testalongnamethatdoesnotmakesense", "1234") |
| 35 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 36 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-374f33fe84ab0ed84dcdebe3")) |
| 37 | }) |
| 38 | |
| 39 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must be predictable", func() { |
| 40 | chain1 := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("testalongnamethatdoesnotmakesense", "1234") |
| 41 | chain2 := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("testalongnamethatdoesnotmakesense", "1234") |
| 42 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 43 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain2).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 44 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(chain2)) |
| 45 | }) |
| 46 | |
| 47 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must change when a character changes", func() { |
| 48 | chain1 := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("testalongnamethatdoesnotmakesense", "1234") |
| 49 | chain2 := FormatChainNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/FormatChainName().("testalongnamethatdoesnotmakesense", "1235") |
| 50 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 51 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain2).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 52 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-374f33fe84ab0ed84dcdebe3")) |
| 53 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(chain2)) |
| 54 | }) |
| 55 | }) |
| 56 | |
| 57 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("MustFormatChainNameWithPrefix", func() { |
| 58 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("generates a chain name with a prefix", func() { |
| 59 | chain := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("test", "1234", "PREFIX-") |
| 60 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 61 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-PREFIX-2bbe0c48b91a7d1b8")) |
| 62 | }) |
| 63 | |
| 64 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must format a short name", func() { |
| 65 | chain := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("test", "1234", "PREFIX-") |
| 66 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 67 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-PREFIX-2bbe0c48b91a7d1b8")) |
| 68 | }) |
| 69 | |
| 70 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must truncate a long name", func() { |
| 71 | chain := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("testalongnamethatdoesnotmakesense", "1234", "PREFIX-") |
| 72 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 73 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-PREFIX-374f33fe84ab0ed84")) |
| 74 | }) |
| 75 | |
| 76 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must be predictable", func() { |
| 77 | chain1 := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("testalongnamethatdoesnotmakesense", "1234", "PREFIX-") |
| 78 | chain2 := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("testalongnamethatdoesnotmakesense", "1234", "PREFIX-") |
| 79 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 80 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain2).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 81 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(chain2)) |
| 82 | }) |
| 83 | |
| 84 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("must change when a character changes", func() { |
| 85 | chain1 := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("testalongnamethatdoesnotmakesense", "1234", "PREFIX-") |
| 86 | chain2 := MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("testalongnamethatdoesnotmakesense", "1235", "PREFIX-") |
| 87 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 88 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain2).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(maxChainLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/maxChainLength.)) |
| 89 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("CNI-PREFIX-374f33fe84ab0ed84")) |
| 90 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(chain1).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(chain2)) |
| 91 | }) |
| 92 | |
| 93 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("panics when prefix is too large", func() { |
| 94 | longPrefix := stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.2 strings/Repeat().("PREFIX-", 4) |
| 95 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(func() { |
| 96 | MustFormatChainNameWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatChainNameWithPrefix().("test", "1234", longPrefix) |
| 97 | }).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Panicscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Panic().()) |
| 98 | }) |
| 99 | }) |
| 100 | |
| 101 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("MustFormatHashWithPrefix", func() { |
| 102 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("always returns a string with the given prefix", func() { |
| 103 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "AAA", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HavePrefixscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HavePrefix().("AAA")) |
| 104 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "foo", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HavePrefixscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HavePrefix().("foo")) |
| 105 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "bar", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HavePrefixscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HavePrefix().("bar")) |
| 106 | }) |
| 107 | |
| 108 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("always returns a string of the given length", func() { |
| 109 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "AAA", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(10)) |
| 110 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(15, "AAA", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(15)) |
| 111 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(5, "AAA", "some string")).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(5)) |
| 112 | }) |
| 113 | |
| 114 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("is deterministic", func() { |
| 115 | val1 := MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "AAA", "some string") |
| 116 | val2 := MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "AAA", "some string") |
| 117 | val3 := MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(10, "AAA", "some string") |
| 118 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(val1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(val2)) |
| 119 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(val1).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(val3)) |
| 120 | }) |
| 121 | |
| 122 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("is (nearly) perfect (injective function)", func() { |
| 123 | hashes := map[string]int{} |
| 124 | |
| 125 | for i := 0; i < 1000; i++ { |
| 126 | name := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("string %d", i) |
| 127 | hashes[MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(8, "", name)]++ |
| 128 | } |
| 129 | |
| 130 | for key, count := range hashes { |
| 131 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(count).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(1), "for key "+key+" got non-unique correspondence") |
| 132 | } |
| 133 | }) |
| 134 | |
| 135 | assertPanicWith := func(fscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:f. func(), expectedErrorMessagescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:expectedErrorMessage. string) { |
| 136 | defer func() { |
| 137 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(recover()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(expectedErrorMessagescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:expectedErrorMessage.)) |
| 138 | }() |
| 139 | fscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/_:f.() |
| 140 | Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().("function should have panicked but did not") |
| 141 | } |
| 142 | |
| 143 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("panics when prefix is longer than the length", func() { |
| 144 | assertPanicWith( |
| 145 | func() { MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(3, "AAA", "some string") }, |
| 146 | "invalid length", |
| 147 | ) |
| 148 | }) |
| 149 | |
| 150 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("panics when length is not positive", func() { |
| 151 | assertPanicWith( |
| 152 | func() { MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(0, "", "some string") }, |
| 153 | "invalid length", |
| 154 | ) |
| 155 | }) |
| 156 | |
| 157 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("panics when length is larger than MaxLen", func() { |
| 158 | assertPanicWith( |
| 159 | func() { MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(MaxHashLenscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MaxHashLen.+1, "", "some string") }, |
| 160 | "invalid length", |
| 161 | ) |
| 162 | }) |
| 163 | }) |
| 164 | }) |