github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/util/system/version_linux_test.go (about) 1 // +build unit 2 // +build linux 3 4 package system 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 const UbuntuOsRelease = ` 13 NAME="Ubuntu" 14 VERSION="18.04.4 LTS (Bionic Beaver)" 15 ID=ubuntu 16 ID_LIKE=debian 17 PRETTY_NAME="Ubuntu 18.04.4 LTS" 18 VERSION_ID="18.04" 19 HOME_URL="https://www.ubuntu.com/" 20 SUPPORT_URL="https://help.ubuntu.com/" 21 BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" 22 PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" 23 VERSION_CODENAME=bionic 24 UBUNTU_CODENAME=bionic 25 ` 26 27 // MockUbuntuReleaseGetter provides to mock Ubuntu file. 28 type MockUbuntuReleaseGetter struct{} 29 30 func (m *MockUbuntuReleaseGetter) GetFileContents(file string) (string, error) { 31 switch file { 32 case "/etc/os-release": 33 return UbuntuOsRelease, nil 34 default: 35 return "Ubuntu 18.04.4 LTS", nil 36 } 37 } 38 39 func TestGetOsVersionReturnsNoErrorWithMock(t *testing.T) { 40 t.Parallel() 41 42 ubuntu := &MockUbuntuReleaseGetter{} 43 SetReleaseGetter(ubuntu) 44 ver, err := GetOsVersion() 45 assert.NoError(t, err) 46 assert.NotNil(t, ver) 47 assert.Equal(t, "Ubuntu 18.04.4 LTS", ver) 48 }