MCPcopy Create free account
hub / github.com/Facets-cloud/flow / TestCmdWorkdirList

Function TestCmdWorkdirList

internal/app/workdir_test.go:85–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestCmdWorkdirList(t *testing.T) {
86 root := setupArchiveTestEnv(t)
87 db := reopenArchiveTestDB(t, root)
88
89 a := filepath.Join(t.TempDir(), "a")
90 b := filepath.Join(t.TempDir(), "b")
91 for _, p := range []string{a, b} {
92 if err := os.MkdirAll(p, 0o755); err != nil {
93 t.Fatal(err)
94 }
95 }
96 if rc := cmdWorkdir([]string{"add", a}); rc != 0 {
97 t.Fatalf("add a rc=%d", rc)
98 }
99 if rc := cmdWorkdir([]string{"add", b}); rc != 0 {
100 t.Fatalf("add b rc=%d", rc)
101 }
102
103 // Force a to be older so b comes first.
104 if _, err := db.Exec("UPDATE workdirs SET last_used_at='2000-01-01T00:00:00Z' WHERE path=?", a); err != nil {
105 t.Fatal(err)
106 }
107 list, err := flowdb.ListWorkdirs(db)
108 if err != nil {
109 t.Fatal(err)
110 }
111 if len(list) != 2 {
112 t.Fatalf("want 2 workdirs, got %d", len(list))
113 }
114 if list[0].Path != b || list[1].Path != a {
115 t.Errorf("order: got [%s, %s], want [%s, %s]", list[0].Path, list[1].Path, b, a)
116 }
117
118 // Invoke the list command to ensure it doesn't crash on real rows.
119 if rc := cmdWorkdir([]string{"list"}); rc != 0 {
120 t.Errorf("list rc=%d", rc)
121 }
122}
123
124func TestCmdWorkdirRemove(t *testing.T) {
125 root := setupArchiveTestEnv(t)

Callers

nothing calls this directly

Calls 4

ListWorkdirsFunction · 0.92
setupArchiveTestEnvFunction · 0.85
reopenArchiveTestDBFunction · 0.85
cmdWorkdirFunction · 0.85

Tested by

no test coverage detected