-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_test.go
More file actions
43 lines (39 loc) · 1.06 KB
/
index_test.go
File metadata and controls
43 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cli
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestIndexRejectsNonDirectory(t *testing.T) {
cmd := NewRootCommand()
cmd.SetArgs([]string{"index", "/this/path/does/not/exist"})
var out, errBuf bytes.Buffer
cmd.SetOut(&out)
cmd.SetErr(&errBuf)
err := cmd.Execute()
if err == nil {
t.Fatal("expected error on missing path arg")
}
}
func TestIndexSmokeRun(t *testing.T) {
dir := t.TempDir()
_ = os.WriteFile(filepath.Join(dir, "a.java"), []byte("public class A {}"), 0644)
cmd := NewRootCommand()
cmd.SetArgs([]string{"index", dir})
var out bytes.Buffer
cmd.SetOut(&out)
cmd.SetErr(&out)
if err := cmd.Execute(); err != nil {
t.Fatalf("index errored: %v\n%s", err, out.String())
}
if !strings.Contains(out.String(), "Files:") {
t.Fatalf("expected stats summary in output:\n%s", out.String())
}
// Cache file should exist under <path>/.codeiq/cache/codeiq.sqlite.
wantFile := filepath.Join(dir, ".codeiq", "cache", "codeiq.sqlite")
if _, err := os.Stat(wantFile); err != nil {
t.Fatalf("cache file missing: %v", err)
}
}