Skip to content

Commit

Permalink
os_release_test.go: Added TestParseOSSupportEnd.
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Davies <jpds@protonmail.com>
  • Loading branch information
jpds committed Apr 2, 2024
1 parent 482a3f0 commit 926508b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions collector/os_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
`

const nixosTapir string = `BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="23.11.20240328.219951b"
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 23.11 (Tapir)"
SUPPORT_END="2024-06-30"
SUPPORT_URL="https://nixos.org/community.html"
VERSION="23.11 (Tapir)"
VERSION_CODENAME=tapir
VERSION_ID="23.11"
`

func TestParseOSRelease(t *testing.T) {
want := &osRelease{
Name: "Ubuntu",
ID: "ubuntu",
IDLike: "debian",
PrettyName: "Ubuntu 20.04.2 LTS",
SupportEnd: "",
Version: "20.04.2 LTS (Focal Fossa)",
VersionID: "20.04",
VersionCodename: "focal",
Expand Down Expand Up @@ -75,6 +91,32 @@ func TestParseOSRelease(t *testing.T) {
}
}

func TestParseOSSupportEnd(t *testing.T) {
want := &osRelease{
BuildID: "23.11.20240328.219951b",
Name: "NixOS",
ID: "nixos",
IDLike: "",
ImageID: "",
ImageVersion: "",
PrettyName: "NixOS 23.11 (Tapir)",
SupportEnd: "2024-06-30",
Variant: "",
VariantID: "",
Version: "23.11 (Tapir)",
VersionID: "23.11",
VersionCodename: "tapir",
}

got, err := parseOSRelease(strings.NewReader(nixosTapir))
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("should have %+v osRelease: got %+v", want, got)
}
}

func TestUpdateStruct(t *testing.T) {
wantedOS := &osRelease{
Name: "Ubuntu",
Expand Down

0 comments on commit 926508b

Please sign in to comment.