41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestListShowsAliasRows(t *testing.T) {
|
|
root := t.TempDir()
|
|
cache, base := filepath.Join(root, "cache"), filepath.Join(root, "code")
|
|
wt := filepath.Join(cache, "worktrees", "unkin", "abc123-0123456789ab")
|
|
for _, d := range []string{wt, base} {
|
|
if err := os.MkdirAll(d, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for _, e := range []string{"develop", "production"} {
|
|
if err := os.Symlink(wt, filepath.Join(base, e)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
cfg := filepath.Join(root, "r10k.yaml")
|
|
y := "cachedir: " + cache + "\nw10k: {aliases: {production: develop}}\nsources: {unkin: {remote: r, basedir: " + base + "}}\n"
|
|
if err := os.WriteFile(cfg, []byte(y), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var out bytes.Buffer
|
|
cmd := rootCmd()
|
|
cmd.SetOut(&out)
|
|
cmd.SetArgs([]string{"-c", cfg, "list"})
|
|
if err := cmd.Execute(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := "unkin\tdevelop\tabc123\nunkin\tproduction\tabc123\talias of develop\n"
|
|
if out.String() != want {
|
|
t.Fatalf("list:\n%q\nwant\n%q", out.String(), want)
|
|
}
|
|
}
|