Add unit test for archTag()
parent
5cc965921a
commit
839bd03621
|
@ -122,7 +122,10 @@ func etcd(v semver.Version, mirror string) string {
|
||||||
|
|
||||||
// archTag returns a CPU architecture suffix for images
|
// archTag returns a CPU architecture suffix for images
|
||||||
func archTag(needsArchSuffix bool) string {
|
func archTag(needsArchSuffix bool) string {
|
||||||
if runtime.GOARCH == "amd64" || !needsArchSuffix {
|
return archTagInt(runtime.GOARCH, needsArchSuffix)
|
||||||
|
}
|
||||||
|
func archTagInt(arch string, needsArchSuffix bool) string {
|
||||||
|
if arch == "amd64" || !needsArchSuffix {
|
||||||
return ":"
|
return ":"
|
||||||
}
|
}
|
||||||
return "-" + runtime.GOARCH + ":"
|
return "-" + runtime.GOARCH + ":"
|
||||||
|
|
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||||
package images
|
package images
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
@ -45,3 +47,30 @@ func TestAuxiliaryMirror(t *testing.T) {
|
||||||
t.Errorf("images mismatch (-want +got):\n%s", diff)
|
t.Errorf("images mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArchTag(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
arch string
|
||||||
|
suffix bool
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"amd64", true, ":",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"amd64", false, ":",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arm64", false, ":",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arm64", true, fmt.Sprintf("-%s:", runtime.GOARCH),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
if tag := archTagInt(test.arch, test.suffix); tag != test.expected {
|
||||||
|
t.Errorf("For arch: %v and suffix flag: '%v' expected %v got %v",
|
||||||
|
test.arch, test.suffix, test.expected, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue