-
Notifications
You must be signed in to change notification settings - Fork 19
/
main_test.go
75 lines (66 loc) · 1.98 KB
/
main_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"io/ioutil"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Helcaraxan/gomod/internal/printer"
"github.com/Helcaraxan/gomod/internal/testutil"
)
var regenerate = flag.Bool("regenerate", false, "Instead of testing the output, use the generated output to refresh the golden images.")
func TestGraphGeneration(t *testing.T) {
testcases := map[string]struct {
expectedFileBase string
dotArgs *graphArgs
}{
"Full": {
expectedFileBase: "full",
dotArgs: &graphArgs{
query: "deps(github.com/Helcaraxan/gomod:test)",
style: &printer.StyleOptions{
ScaleNodes: true,
Cluster: printer.Full,
},
},
},
"Shared": {
expectedFileBase: "shared-dependencies",
dotArgs: &graphArgs{
query: "shared(deps(github.com/Helcaraxan/gomod))",
style: &printer.StyleOptions{},
},
},
"TargetDependency": {
expectedFileBase: "dependency-chains",
dotArgs: &graphArgs{
annotate: true,
query: "rdeps(github.com/stretchr/testify)",
style: &printer.StyleOptions{},
},
},
}
for name := range testcases {
testcase := testcases[name]
t.Run(name, func(t *testing.T) {
tempDir := t.TempDir()
cArgs := &commonArgs{log: testutil.TestLogger(t)}
// Test the dot generation.
dotArgs := *testcase.dotArgs
dotArgs.commonArgs = cArgs
dotArgs.outputPath = filepath.Join(tempDir, testcase.expectedFileBase+".dot")
require.NoError(t, runGraphCmd(&dotArgs))
actual, err := ioutil.ReadFile(filepath.Join(tempDir, testcase.expectedFileBase+".dot"))
require.NoError(t, err)
if *regenerate {
require.NoError(t, ioutil.WriteFile(filepath.Join("images", testcase.expectedFileBase+".dot"), actual, 0644))
} else {
var expected []byte
expected, err = ioutil.ReadFile(filepath.Join("images", testcase.expectedFileBase+".dot"))
require.NoError(t, err)
assert.Equal(t, string(expected), string(actual))
}
})
}
}