2023-05-12 17:26:53 +00:00
|
|
|
package debian
|
|
|
|
|
|
|
|
import (
|
2023-05-13 12:56:25 +00:00
|
|
|
"os"
|
2023-05-12 17:26:53 +00:00
|
|
|
"testing"
|
2023-05-13 11:00:34 +00:00
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2023-05-18 16:07:24 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro"
|
2023-05-13 12:56:25 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/fs"
|
2023-05-12 17:26:53 +00:00
|
|
|
)
|
|
|
|
|
2023-05-18 12:52:52 +00:00
|
|
|
func TestMatch(t *testing.T) {
|
2023-05-14 17:34:49 +00:00
|
|
|
if os.Getenv("CI") != "" {
|
|
|
|
t.Skip("skip testing in CI")
|
|
|
|
}
|
|
|
|
|
2023-05-13 11:00:34 +00:00
|
|
|
t.Log("tested with cache by default")
|
|
|
|
|
2023-05-13 12:56:25 +00:00
|
|
|
tmp, err := fs.TempDir()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmp)
|
|
|
|
|
|
|
|
config.Directory = tmp
|
|
|
|
|
2023-05-18 18:27:51 +00:00
|
|
|
km := config.Target{
|
2023-05-18 18:48:09 +00:00
|
|
|
Distro: distro.Distro{Release: "7"},
|
|
|
|
Kernel: config.Kernel{Regex: "3.2.0-4"},
|
2023-05-13 11:00:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 12:52:52 +00:00
|
|
|
pkgs, err := Match(km)
|
2023-05-13 11:00:34 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pkgs) == 0 {
|
|
|
|
t.Fatal("no packages")
|
|
|
|
}
|
|
|
|
}
|
2023-05-12 20:05:44 +00:00
|
|
|
|
|
|
|
func TestKernelRelease(t *testing.T) {
|
|
|
|
type testcase struct {
|
|
|
|
Deb string
|
|
|
|
Release Release
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range []testcase{
|
|
|
|
testcase{"linux-image-3.2.0-0.bpo.4-amd64_3.2.41-2+deb7u2~bpo60+1_amd64", Wheezy},
|
2023-05-14 10:30:35 +00:00
|
|
|
testcase{"linux-image-3.15-trunk-amd64_3.15.5-1~exp1_amd64", Jessie},
|
2023-05-13 17:32:02 +00:00
|
|
|
testcase{"linux-image-3.16-rc5-amd64_3.16~rc5-1~exp1_amd64", Jessie},
|
|
|
|
testcase{"linux-image-4.15.0-3-amd64_4.15.17-1_amd64", Stretch},
|
|
|
|
testcase{"linux-image-4.16.0-rc5-amd64_4.16~rc5-1~exp1_amd64", Stretch},
|
2023-05-14 10:30:35 +00:00
|
|
|
testcase{"linux-image-4.17.0-2-amd64", Stretch},
|
2023-05-13 17:32:02 +00:00
|
|
|
testcase{"linux-image-4.18.0-0.bpo.3-amd64_4.18.20-2~bpo9+1_amd64", Stretch},
|
|
|
|
testcase{"linux-image-4.19.0-rc2-amd64-unsigned_4.19~rc2-1~exp1_amd64", Buster},
|
|
|
|
testcase{"linux-image-4.20.0-trunk-amd64-unsigned_4.20-1~exp1_amd64", Buster},
|
2023-05-14 10:30:35 +00:00
|
|
|
testcase{"linux-image-4.8.0-2-amd64-unsigned_4.8.15-2_amd64", Jessie},
|
|
|
|
testcase{"linux-image-4.9.0-rc3-amd64-unsigned_4.9~rc3-1~exp1_amd64", Stretch},
|
2023-05-13 17:32:02 +00:00
|
|
|
testcase{"linux-image-5.0.0-trunk-amd64-unsigned_5.0.1-1~exp1_amd64", Buster},
|
|
|
|
testcase{"linux-image-5.9.0-rc4-amd64-unsigned_5.9~rc4-1~exp1_amd64", Buster},
|
|
|
|
testcase{"linux-image-5.10.0-rc4-amd64-unsigned_5.10~rc4-1~exp1_amd64", Bullseye},
|
2023-05-14 10:30:35 +00:00
|
|
|
testcase{"linux-image-5.16.0-rc5-amd64-unsigned_5.16~rc5-1~exp1_amd64", Bullseye},
|
|
|
|
testcase{"linux-image-6.1.0-0.deb11.7-amd64-unsigned", Bullseye},
|
|
|
|
testcase{"linux-image-6.1.0-8-amd64-unsigned", Bullseye},
|
2023-05-12 20:05:44 +00:00
|
|
|
} {
|
|
|
|
r, err := kernelRelease(tc.Deb)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if r != tc.Release {
|
|
|
|
t.Fatalf("%v -> %v != %v", tc.Deb, r, tc.Release)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|