modified TestGoVersion to check Go CPU architectue (#273)
* modified TestGoVersion to check go cpu architectue
* removed os.exec(go version) with runtime.Version
* added cpu arch check via uintptr
* modified the test message
* updated changes.md
diff --git a/CHANGES.md b/CHANGES.md
index 8b52092..b7afd9d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -27,6 +27,7 @@
- Bump go to 1.20.
- Set KV's minimum memtable size to 8MB
- [docs] Fix docs crud examples error
+- Modified `TestGoVersion` to check for CPU architecture and Go Version
## 0.3.1
diff --git a/scripts/ci/check/version_test.go b/scripts/ci/check/version_test.go
index b02ac05..3085dd5 100644
--- a/scripts/ci/check/version_test.go
+++ b/scripts/ci/check/version_test.go
@@ -21,6 +21,8 @@
"fmt"
"os"
"os/exec"
+ "regexp"
+ "runtime"
"strings"
"testing"
@@ -28,15 +30,25 @@
"golang.org/x/mod/modfile"
)
-const GoVersion = "1.20"
+const (
+ GoVersion = "1.20"
+ CPUType = 8
+)
func TestGoVersion(t *testing.T) {
- goversion, err := exec.Command("go", "version").Output()
- require.NoError(t, err)
+ // the value of ptr will be 8 for 64 bit system and 4 for 32 bit system
+ ptr := 4 << (^uintptr(0) >> 63)
+ require.Equal(t, CPUType, ptr, "This CPU architectue is not supported, it should be a 64 bits Go version")
- currentVersion := strings.Split(string(goversion), " ")[2][2:]
+ currentVersion := runtime.Version()
+ versionRegex := regexp.MustCompile(`go(\d+\.\d+\.\d)`)
+ matches := versionRegex.FindStringSubmatch(currentVersion)
- currentMajorMinor, currentPatch := splitVersion(currentVersion)
+ require.GreaterOrEqual(t, len(matches), 2)
+
+ versionNumber := matches[1]
+
+ currentMajorMinor, currentPatch := splitVersion(versionNumber)
expectedMajorMinor, expectedPatch := splitVersion(GoVersion)
require.Equal(t, currentMajorMinor, expectedMajorMinor,