-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpact_test.go
More file actions
70 lines (65 loc) · 2.32 KB
/
Copy pathimpact_test.go
File metadata and controls
70 lines (65 loc) · 2.32 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package repomap
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestImpactReportsLocalFacts(t *testing.T) {
t.Parallel()
m := New("/repo", DefaultConfig())
m.ranked = []RankedFile{
{
FileSymbols: &FileSymbols{
Path: "internal/auth/token.go",
Language: "go",
Package: "auth",
ImportPath: "example.com/app/internal/auth",
ParseMethod: "go_ast",
Imports: []string{"sync"},
Symbols: []Symbol{
{Name: "RefreshToken", Kind: "function", Exported: true},
{Name: "helper", Kind: "function", Exported: false},
},
},
Score: 30,
ScoreComponents: map[string]int{scoreComponentSymbols: 1, scoreComponentImports: 20},
Boundaries: []string{"HTTP"},
},
{
FileSymbols: &FileSymbols{
Path: "internal/http/middleware.go",
Language: "go",
Package: "http",
ImportPath: "example.com/app/internal/http",
Imports: []string{"example.com/app/internal/auth"},
},
},
{
FileSymbols: &FileSymbols{
Path: "internal/auth/token_test.go",
Language: "go",
Package: "auth",
ImportPath: "example.com/app/internal/auth",
Symbols: []Symbol{{Name: "TestRefreshToken", Kind: "function"}},
},
},
}
impact, err := m.Impact("internal/auth/token.go")
require.NoError(t, err)
assert.Equal(t, "internal/auth/token.go", impact.File.Path)
assert.Equal(t, "go_ast", impact.ParseMethod)
assert.Equal(t, []string{"sync"}, impact.Imports)
assert.Equal(t, []string{"internal/http/middleware.go"}, impact.ImportedBy)
assert.Equal(t, []string{"internal/auth/token_test.go"}, impact.Tests)
require.Len(t, impact.ExportedSymbols, 1)
assert.Equal(t, "RefreshToken", impact.ExportedSymbols[0].Name)
assert.Equal(t, []string{"HTTP"}, impact.Boundaries)
assert.Equal(t, 20, impact.ScoreComponents[scoreComponentImports])
assert.Equal(t, "medium", impact.RiskLevel)
assert.Equal(t, []string{"auth", "http"}, impact.AffectedPackages)
assert.Contains(t, impact.CheckNext, "inspect importer internal/http/middleware.go")
assert.Equal(t, []string{"go test ./internal/auth"}, impact.LikelyTestCommands)
require.NotEmpty(t, impact.ReadNext)
assert.Equal(t, "internal/auth/token.go", impact.ReadNext[0].File)
assert.Equal(t, "inspect target file", impact.ReadNext[0].Reason)
}