48 lines
894 B
Go
48 lines
894 B
Go
package pkg
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestUnknownDistribution(t *testing.T) {
|
|
|
|
_, err := Load("invalid-distro-xxx")
|
|
if err != ErrUnknownDistribution {
|
|
t.Errorf("expected <%s>, got <%s>", ErrUnknownDistribution, err)
|
|
t.Fail()
|
|
}
|
|
|
|
}
|
|
func TestNoCandidateInstalled(t *testing.T) {
|
|
|
|
// get host distro
|
|
out, err := exec.Command("lsb_release", "-is").Output()
|
|
if err != nil {
|
|
t.Errorf("cannot get host linux distribution")
|
|
t.Fail()
|
|
}
|
|
hostDistro := strings.ToLower(strings.Trim(string(out), " \n\t"))
|
|
|
|
// valid candidate
|
|
_, err = Load(hostDistro)
|
|
if err != nil {
|
|
t.Errorf("expected <nil>, got <%s>", err)
|
|
t.Fail()
|
|
}
|
|
|
|
// invalid candidate
|
|
distro := "solus"
|
|
if hostDistro == distro {
|
|
distro = "ubuntu"
|
|
}
|
|
|
|
_, err = Load(distro)
|
|
if err != ErrNoCandidateInstalled {
|
|
t.Errorf("expected <%s>, got <%s>", ErrNoCandidateInstalled, err)
|
|
t.Fail()
|
|
}
|
|
|
|
}
|