tests(aa-log): add missing tests for osrelease.

This commit is contained in:
Alexandre Pujol 2024-02-28 23:27:57 +00:00
parent ae9f7e7442
commit 58f130fbb2
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
2 changed files with 59 additions and 1 deletions

View File

@ -18,7 +18,7 @@ var (
"arch": {},
"debian": {},
"ubuntu": {},
"opensuse": {"suse"},
"opensuse": {"suse", "opensuse-tumbleweed"},
"whonix": {},
}

View File

@ -5,6 +5,7 @@
package prebuild
import (
"reflect"
"testing"
"github.com/arduino/go-paths-helper"
@ -78,6 +79,63 @@ ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon`
)
func TestNewOSRelease(t *testing.T) {
tests := []struct {
name string
osRelease string
want map[string]string
}{
{
name: "Archlinux",
osRelease: Archlinux,
want: map[string]string{
"NAME": "Arch Linux",
"PRETTY_NAME": "Arch Linux",
"ID": "arch",
"BUILD_ID": "rolling",
"ANSI_COLOR": "38;2;23;147;209",
"HOME_URL": "https://archlinux.org/",
"DOCUMENTATION_URL": "https://wiki.archlinux.org/",
"SUPPORT_URL": "https://bbs.archlinux.org/",
"BUG_REPORT_URL": "https://bugs.archlinux.org/",
"PRIVACY_POLICY_URL": "https://terms.archlinux.org/docs/privacy-policy/",
"LOGO": "archlinux-logo",
},
},
{
name: "Ubuntu",
osRelease: Ubuntu,
want: map[string]string{
"PRETTY_NAME": "Ubuntu 22.04.2 LTS",
"NAME": "Ubuntu",
"VERSION_ID": "22.04",
"VERSION": "22.04.2 LTS (Jammy Jellyfish)",
"VERSION_CODENAME": "jammy",
"ID": "ubuntu",
"ID_LIKE": "debian",
"HOME_URL": "https://www.ubuntu.com/",
"SUPPORT_URL": "https://help.ubuntu.com/",
"BUG_REPORT_URL": "https://bugs.launchpad.net/ubuntu/",
"PRIVACY_POLICY_URL": "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
"UBUNTU_CODENAME": "jammy",
},
},
}
osReleaseFile = "/tmp/os-release"
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := paths.New(osReleaseFile).WriteFile([]byte(tt.osRelease))
if err != nil {
return
}
if got := NewOSRelease(); !reflect.DeepEqual(got, tt.want) {
pp.Print(got)
t.Errorf("NewOSRelease() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getSupportedDistribution(t *testing.T) {
tests := []struct {
name string