tests: add coverage for common/helpers.go
This also changes the helpers.go to enable mocking all the different architectures.
This commit is contained in:
parent
09109b4f8e
commit
1cf2af10d0
2 changed files with 53 additions and 4 deletions
|
|
@ -2,14 +2,16 @@ package common
|
|||
|
||||
import "runtime"
|
||||
|
||||
var RuntimeGOARCH = runtime.GOARCH
|
||||
|
||||
func CurrentArch() string {
|
||||
if runtime.GOARCH == "amd64" {
|
||||
if RuntimeGOARCH == "amd64" {
|
||||
return "x86_64"
|
||||
} else if runtime.GOARCH == "arm64" {
|
||||
} else if RuntimeGOARCH == "arm64" {
|
||||
return "aarch64"
|
||||
} else if runtime.GOARCH == "ppc64le" {
|
||||
} else if RuntimeGOARCH == "ppc64le" {
|
||||
return "ppc64le"
|
||||
} else if runtime.GOARCH == "s390x" {
|
||||
} else if RuntimeGOARCH == "s390x" {
|
||||
return "s390x"
|
||||
} else {
|
||||
panic("unsupported architecture")
|
||||
|
|
|
|||
47
internal/common/helpers_test.go
Normal file
47
internal/common/helpers_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCurrentArchAMD64(t *testing.T) {
|
||||
origRuntimeGOARCH := RuntimeGOARCH
|
||||
defer func() { RuntimeGOARCH = origRuntimeGOARCH }()
|
||||
RuntimeGOARCH = "amd64"
|
||||
assert.Equal(t, "x86_64", CurrentArch())
|
||||
}
|
||||
|
||||
func TestCurrentArchARM64(t *testing.T) {
|
||||
origRuntimeGOARCH := RuntimeGOARCH
|
||||
defer func() { RuntimeGOARCH = origRuntimeGOARCH }()
|
||||
RuntimeGOARCH = "arm64"
|
||||
assert.Equal(t, "aarch64", CurrentArch())
|
||||
}
|
||||
|
||||
func TestCurrentArchPPC64LE(t *testing.T) {
|
||||
origRuntimeGOARCH := RuntimeGOARCH
|
||||
defer func() { RuntimeGOARCH = origRuntimeGOARCH }()
|
||||
RuntimeGOARCH = "ppc64le"
|
||||
assert.Equal(t, "ppc64le", CurrentArch())
|
||||
}
|
||||
|
||||
func TestCurrentArchS390X(t *testing.T) {
|
||||
origRuntimeGOARCH := RuntimeGOARCH
|
||||
defer func() { RuntimeGOARCH = origRuntimeGOARCH }()
|
||||
RuntimeGOARCH = "s390x"
|
||||
assert.Equal(t, "s390x", CurrentArch())
|
||||
}
|
||||
|
||||
func TestCurrentArchUnsupported(t *testing.T) {
|
||||
origRuntimeGOARCH := RuntimeGOARCH
|
||||
defer func() { RuntimeGOARCH = origRuntimeGOARCH }()
|
||||
RuntimeGOARCH = "UKNOWN"
|
||||
assert.PanicsWithValue(t, "unsupported architecture", func() { CurrentArch() })
|
||||
}
|
||||
|
||||
func TestPanicOnError(t *testing.T) {
|
||||
err := errors.New("Error message")
|
||||
assert.PanicsWithValue(t, err, func() { PanicOnError(err) })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue