40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package nginxsetup
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReleaseSelectsOnlySupportedPackageCommands(t *testing.T) {
|
|
for _, tc := range []struct{ raw, manager, install string }{
|
|
{"NAME=Ubuntu\nID=ubuntu\nVERSION_ID=24.04\n", "apt-get", "apt-get install -y nginx certbot"},
|
|
{"NAME=\"TencentOS Server\"\nVERSION=\"4\"\nID=tencentos\nVERSION_ID=\"4\"\n", "dnf", "dnf install -y nginx certbot"},
|
|
{"ID=tencentos\nVERSION_ID=3\n", "", ""},
|
|
{"ID=debian\nVERSION_ID=12\n", "", ""},
|
|
} {
|
|
id, version := ParseOSRelease(tc.raw)
|
|
pm, commands := Plan(id, version)
|
|
if pm != tc.manager {
|
|
t.Errorf("%s: package manager %q", id, pm)
|
|
}
|
|
if tc.install != "" {
|
|
got := strings.Join(commands[len(commands)-1], " ")
|
|
if got != tc.install {
|
|
t.Errorf("%s: install command %q", id, got)
|
|
}
|
|
} else if len(commands) != 0 {
|
|
t.Errorf("%s should be unsupported", id)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOnlyOneInitializationAtATime(t *testing.T) {
|
|
if !Begin() {
|
|
t.Fatal("first initialization rejected")
|
|
}
|
|
defer End()
|
|
if Begin() {
|
|
t.Fatal("concurrent initialization accepted")
|
|
}
|
|
}
|