-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfiles_test.go
More file actions
52 lines (47 loc) · 1.74 KB
/
files_test.go
File metadata and controls
52 lines (47 loc) · 1.74 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
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFileList(t *testing.T) {
found := []string{}
searchDir := expandPath(".")
require.NoError(t, runOnFiles(context.TODO(), []string{searchDir}, []string{"go.mod", "go.sum"}, func(file string) error {
found = append(found, file)
return nil
}))
require.Contains(t, found, expandPath("./files_test.go"))
require.Contains(t, found, expandPath("./main.go"))
require.NotContains(t, found, expandPath("./go.mod"))
require.NotContains(t, found, expandPath("./go.sum"))
}
func TestExports(t *testing.T) {
searchDir := expandPath("./internal/dummy/")
exports, err := findExports(context.TODO(), []string{searchDir}, []string{})
require.NoError(t, err)
if _, ok := exports["github.com/launchdarkly-labs/refaudit/internal/dummy.ExportedFunction"]; !ok {
assert.FailNow(t, "missing exported function")
}
if _, ok := exports["github.com/launchdarkly-labs/refaudit/internal/dummy.ExportedVariable"]; !ok {
assert.FailNow(t, "missing exported variable")
}
if _, ok := exports["github.com/launchdarkly-labs/refaudit/internal/dummy.ExportedStruct"]; !ok {
assert.FailNow(t, "missing exported struct")
}
if _, ok := exports["github.com/launchdarkly-labs/refaudit/internal/dummy.ExportedInterface"]; !ok {
assert.FailNow(t, "missing exported interface")
}
}
func TestImports(t *testing.T) {
searchDir := expandPath("./internal/dummy/")
imports, err := findImports(context.TODO(), []string{searchDir}, []string{})
require.NoError(t, err)
if _, ok := imports["fmt.Print"]; !ok {
assert.FailNow(t, "missing imported function call")
}
if _, ok := imports["fmt.Stringer"]; !ok {
assert.FailNow(t, "missing imported interface ref")
}
}