From 58f130fbb20228b43ff6d94dbdeb0340f7eff712 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Wed, 28 Feb 2024 23:27:57 +0000 Subject: [PATCH] tests(aa-log): add missing tests for osrelease. --- pkg/prebuild/tools.go | 2 +- pkg/prebuild/tools_test.go | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/pkg/prebuild/tools.go b/pkg/prebuild/tools.go index 9c548e15..7110f702 100644 --- a/pkg/prebuild/tools.go +++ b/pkg/prebuild/tools.go @@ -18,7 +18,7 @@ var ( "arch": {}, "debian": {}, "ubuntu": {}, - "opensuse": {"suse"}, + "opensuse": {"suse", "opensuse-tumbleweed"}, "whonix": {}, } diff --git a/pkg/prebuild/tools_test.go b/pkg/prebuild/tools_test.go index 6ae01250..f03fd0a8 100644 --- a/pkg/prebuild/tools_test.go +++ b/pkg/prebuild/tools_test.go @@ -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