-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy patharm_test.go
49 lines (43 loc) · 1.14 KB
/
arm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package selfupdate
import (
"fmt"
"os"
"os/exec"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetGOARM(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on windows")
}
t.Parallel()
testCases := []struct {
goOS string
goArch string
goArm string
expectedGoArm uint8
}{
{"linux", "arm", "7", 7},
{"linux", "arm", "6", 6},
{"linux", "arm", "5", 5},
{"linux", "arm", "", 7}, // armv7 is the default
{"linux", "arm64", "", 0},
{"linux", "amd64", "", 0},
{"darwin", "arm64", "", 0},
}
for _, tc := range testCases {
t.Run(tc.goOS+" "+tc.goArch+" "+tc.goArm, func(t *testing.T) {
tempBinary := t.TempDir() + "/tempBinary-" + tc.goOS + tc.goArch + "v" + tc.goArm
buildCmd := fmt.Sprintf("GOOS=%s GOARCH=%s GOARM=%s go build -o %s ./testdata/hello", tc.goOS, tc.goArch, tc.goArm, tempBinary)
cmd := exec.Command("sh", "-c", buildCmd)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
require.NoError(t, err)
goArm := getGOARM(tempBinary)
assert.Equal(t, tc.expectedGoArm, goArm)
})
}
}