github.com/simpleiot/simpleiot@v0.18.3/system/os_version_test.go (about) 1 package system 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/blang/semver/v4" 8 ) 9 10 func TestReadOSRelease(t *testing.T) { 11 /* will only work on some Linux systems 12 rel, err := ReadOSVersion("VERSION") 13 // If there is no error, we have a problem 14 if err != nil { 15 t.Error("Error reading version: ", err) 16 } 17 18 t.Log("/etc/os-release contains a valid version?", rel) 19 */ 20 21 v, err := parseVersion([]byte("VERSION_ID=\"1.2\"\nTesting with quotes"), "VERSION_ID") 22 23 if err != nil { 24 t.Error("Got error parsing version: ", err) 25 } 26 27 exp := semver.Version{ 28 Major: 1, 29 Minor: 2, 30 Patch: 0, 31 } 32 33 if v.NE(exp) { 34 fmt.Printf("got %+v\n", v) 35 t.Error("Did not get expected version") 36 } 37 38 v, err = parseVersion([]byte("VERSION_ID=1.2.352\nTesting without quotes"), "VERSION_ID") 39 exp = semver.Version{ 40 Major: 1, 41 Minor: 2, 42 Patch: 352, 43 } 44 45 if err != nil { 46 t.Error("Got error parsing version: ", err) 47 } 48 49 if v.NE(exp) { 50 fmt.Printf("got %+v\n", v) 51 t.Error("Did not get expected version") 52 } 53 }