debian-forge-composer/internal/common/distro_test.go
Tomas Hozza c7e5e3c9c2 Move GetRedHatRelease() and GetHostDistroName() to common package
The `distro` package is now used for distro definitions supported by
osbuild-composer, not for introspecting the Host system. Move
`GetRedHatRelease()` and `GetHostDistroName()` functions to the `common`
package.
2022-06-10 14:48:18 +01:00

54 lines
1.1 KiB
Go

package common
import (
"reflect"
"strings"
"testing"
)
func TestOSRelease(t *testing.T) {
var cases = []struct {
Input string
OSRelease map[string]string
}{
{
``,
map[string]string{},
},
{
`NAME=Fedora
VERSION="30 (Workstation Edition)"
ID=fedora
VERSION_ID=30
VERSION_CODENAME=""
PLATFORM_ID="platform:f30"
PRETTY_NAME="Fedora 30 (Workstation Edition)"
VARIANT="Workstation Edition"
VARIANT_ID=workstation`,
map[string]string{
"NAME": "Fedora",
"VERSION": "30 (Workstation Edition)",
"ID": "fedora",
"VERSION_ID": "30",
"VERSION_CODENAME": "",
"PLATFORM_ID": "platform:f30",
"PRETTY_NAME": "Fedora 30 (Workstation Edition)",
"VARIANT": "Workstation Edition",
"VARIANT_ID": "workstation",
},
},
}
for i, c := range cases {
r := strings.NewReader(c.Input)
osrelease, err := readOSRelease(r)
if err != nil {
t.Fatalf("%d: readOSRelease: %v", i, err)
}
if !reflect.DeepEqual(osrelease, c.OSRelease) {
t.Fatalf("%d: readOSRelease returned unexpected result: %#v", i, osrelease)
}
}
}