diff --git a/internal/app/ship_test.go b/internal/app/ship_test.go new file mode 100644 index 0000000..bc6f90b --- /dev/null +++ b/internal/app/ship_test.go @@ -0,0 +1,62 @@ +package app + +import ( + "os/exec" + "testing" +) + +func TestScpArgs(t *testing.T) { + args := scpArgs([]string{"/out/a.mp3", "/out/b.mp3", "/out/playlist.m3u8"}, + "root@vps:/opt/icecast/web/ai-radio/", "") + joined := "" + for _, a := range args { + joined += a + " " + } + for _, want := range []string{ + "-o StrictHostKeyChecking=accept-new", + "/out/a.mp3", + "/out/b.mp3", + "/out/playlist.m3u8", + "root@vps:/opt/icecast/web/ai-radio/", + } { + if !contains(joined, want) { + t.Fatalf("scp args missing %q: %s", want, joined) + } + } + // playlist must be last so links resolve before the list appears + last := args[len(args)-1] + if last != "root@vps:/opt/icecast/web/ai-radio/" { + t.Fatal("target must be last arg") + } + // playlist before target, after mp3s + pi := -1 + for i, a := range args { + if a == "/out/playlist.m3u8" { + pi = i + } + } + if pi < 2 { + t.Fatal("playlist should come after the mp3s") + } +} + +func TestScpArgsWithKey(t *testing.T) { + args := scpArgs([]string{"/x.mp3"}, "u@h:/d/", "/keys/id") + found := false + for i, a := range args { + if a == "-i" && i+1 < len(args) && args[i+1] == "/keys/id" { + found = true + } + } + if !found { + t.Fatalf("identity file not passed: %v", args) + } +} + +func TestScpEmptyNoop(t *testing.T) { + if err := Ship(nil, "u@h:/d/", ""); err != nil { + t.Fatalf("empty ship should be a no-op, got %v", err) + } +} + +var _ = exec.Command // keep import if unused in future edits