test: cover absolutizePaths, lastID, runCheckMigrations
Adds focused unit tests for previously-uncovered cli helpers: - TestAbsolutizePaths covers the path-vararg helper's empty, absolute, and relative branches; complements the existing TestAbsolutizeImageRegisterPaths. - TestLastID is table-driven across nil/empty/sorted/unsorted/ duplicates/negative inputs. - TestRunCheckMigrations* exercises every Compatibility branch (compatible / migrations needed / incompatible / inspect error) by stubbing bangerdExit and pointing the layout at a temp-dir DB seeded directly with the schema_migrations table. - TestNewBangerdCommandSubcommands pins the flag set against accidental drift. Lifts internal/cli coverage from 71% to 76% combined. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2606bfbabb
commit
02a1472dd4
2 changed files with 238 additions and 0 deletions
|
|
@ -737,6 +737,50 @@ func TestAbsolutizeImageRegisterPaths(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAbsolutizePaths(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("Getwd: %v", err)
|
||||
}
|
||||
if err := os.Chdir(tmp); err != nil {
|
||||
t.Fatalf("Chdir: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = os.Chdir(wd) })
|
||||
|
||||
empty := ""
|
||||
abs := "/already/absolute/path"
|
||||
rel1 := filepath.Join("a", "b")
|
||||
rel2 := "./c/d"
|
||||
|
||||
if err := absolutizePaths(&empty, &abs, &rel1, &rel2); err != nil {
|
||||
t.Fatalf("absolutizePaths: %v", err)
|
||||
}
|
||||
|
||||
if empty != "" {
|
||||
t.Errorf("empty value mutated: %q", empty)
|
||||
}
|
||||
if abs != "/already/absolute/path" {
|
||||
t.Errorf("absolute value mutated: %q", abs)
|
||||
}
|
||||
if !filepath.IsAbs(rel1) {
|
||||
t.Errorf("rel1 not absolutized: %q", rel1)
|
||||
}
|
||||
if !filepath.IsAbs(rel2) {
|
||||
t.Errorf("rel2 not absolutized: %q", rel2)
|
||||
}
|
||||
// Sanity: relative paths should land under tmp.
|
||||
if !strings.HasPrefix(rel1, tmp) {
|
||||
t.Errorf("rel1 = %q, want prefix %q", rel1, tmp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAbsolutizePathsNoArgs(t *testing.T) {
|
||||
if err := absolutizePaths(); err != nil {
|
||||
t.Fatalf("absolutizePaths() with no args: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintImageListTableShowsRootfsSizes(t *testing.T) {
|
||||
rootfs := filepath.Join(t.TempDir(), "rootfs.ext4")
|
||||
if err := os.WriteFile(rootfs, nil, 0o644); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue