Add unit test for archTag()

pull/9985/head
Ilya Zuyev 2021-01-14 12:28:10 -08:00
parent 5cc965921a
commit 839bd03621
2 changed files with 33 additions and 1 deletions

View File

@ -122,7 +122,10 @@ func etcd(v semver.Version, mirror string) string {
// archTag returns a CPU architecture suffix for images
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 "-" + runtime.GOARCH + ":"

View File

@ -17,6 +17,8 @@ limitations under the License.
package images
import (
"fmt"
"runtime"
"testing"
"github.com/google/go-cmp/cmp"
@ -45,3 +47,30 @@ func TestAuxiliaryMirror(t *testing.T) {
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)
}
}
}