-
Notifications
You must be signed in to change notification settings - Fork 42
test: improve render coverage from 78.5% to 84.4% #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ package render | |||||||||||
|
|
||||||||||||
| import ( | ||||||||||||
| "bytes" | ||||||||||||
| "os" | ||||||||||||
| "path/filepath" | ||||||||||||
| "strings" | ||||||||||||
| "testing" | ||||||||||||
|
|
||||||||||||
|
|
@@ -103,3 +105,73 @@ func TestDepgraphRendersExternalDepsAndSummarySection(t *testing.T) { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func writeDepgraphFixture(t *testing.T, root string) { | ||||||||||||
| t.Helper() | ||||||||||||
|
|
||||||||||||
| files := map[string]string{ | ||||||||||||
| "go.mod": "module example.com/demo\n\ngo 1.24.0\n", | ||||||||||||
| "app/main.go": "package app\n\nimport (\n\t\"example.com/demo/core/extra1\"\n\t\"example.com/demo/core/extra2\"\n\t\"example.com/demo/core/leaf\"\n\t\"example.com/demo/core/mid\"\n\t\"example.com/demo/core/root\"\n)\n\nfunc Main() {\n\textra1.Extra1()\n\textra2.Extra2()\n\tleaf.Leaf()\n\tmid.Mid()\n\troot.Root()\n}\n", | ||||||||||||
| "core/root/root.go": "package root\n\nimport \"example.com/demo/core/mid\"\n\nfunc Root() {\n\tmid.Mid()\n}\n", | ||||||||||||
| "core/mid/mid.go": "package mid\n\nimport \"example.com/demo/core/leaf\"\n\nfunc Mid() {\n\tleaf.Leaf()\n}\n", | ||||||||||||
| "core/leaf/leaf.go": "package leaf\n\nfunc Leaf() {}\n", | ||||||||||||
| "core/extra1/extra1.go": "package extra1\n\nimport \"example.com/demo/core/leaf\"\n\nfunc Extra1() {\n\tleaf.Leaf()\n}\n", | ||||||||||||
| "core/extra2/extra2.go": "package extra2\n\nimport \"example.com/demo/core/leaf\"\n\nfunc Extra2() {\n\tleaf.Leaf()\n}\n", | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| for path, content := range files { | ||||||||||||
| full := filepath.Join(root, path) | ||||||||||||
| if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil { | ||||||||||||
| t.Fatal(err) | ||||||||||||
| } | ||||||||||||
| if err := os.WriteFile(full, []byte(content), 0o644); err != nil { | ||||||||||||
| t.Fatal(err) | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func TestDepgraphRendersChainsFanoutAndHubs(t *testing.T) { | ||||||||||||
| if !scanner.NewAstGrepAnalyzer().Available() { | ||||||||||||
| t.Skip("ast-grep not available") | ||||||||||||
|
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This guard can pass even when ast-grep is not actually installed (for example on many Linux systems where Useful? React with 👍 / 👎. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| root := t.TempDir() | ||||||||||||
| writeDepgraphFixture(t, root) | ||||||||||||
|
|
||||||||||||
| project := scanner.DepsProject{ | ||||||||||||
| Root: root, | ||||||||||||
| Files: []scanner.FileAnalysis{ | ||||||||||||
| {Path: "app/main.go", Functions: []string{"Main"}}, | ||||||||||||
| {Path: "core/root/root.go", Functions: []string{"Root"}}, | ||||||||||||
| {Path: "core/mid/mid.go", Functions: []string{"Mid"}}, | ||||||||||||
| {Path: "core/leaf/leaf.go", Functions: []string{"Leaf"}}, | ||||||||||||
| {Path: "core/extra1/extra1.go", Functions: []string{"Extra1"}}, | ||||||||||||
| {Path: "core/extra2/extra2.go", Functions: []string{"Extra2"}}, | ||||||||||||
| }, | ||||||||||||
| ExternalDeps: map[string][]string{ | ||||||||||||
| "go": {"example.com/very/long/module/name/v2"}, | ||||||||||||
| }, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| var buf bytes.Buffer | ||||||||||||
| Depgraph(&buf, project) | ||||||||||||
| output := buf.String() | ||||||||||||
|
|
||||||||||||
| expectedSnippets := []string{ | ||||||||||||
| "Dependency Flow", | ||||||||||||
| "Go: name", | ||||||||||||
| "App", | ||||||||||||
| "Core", | ||||||||||||
| "main ──┬──▶ core/extra1/extra1", | ||||||||||||
| "└──▶ core/root/root", | ||||||||||||
|
Comment on lines
+165
to
+166
|
||||||||||||
| "main ──┬──▶ core/extra1/extra1", | |
| "└──▶ core/root/root", | |
| "main ──┬──▶", | |
| "core/extra1/extra1", | |
| "core/root/root", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI coverage floor is raised to 50.0 here, but the coverage badge configuration later in this workflow still uses
minColorRange: 45. If the intent is for the badge color scale to reflect the enforced floor, consider updatingminColorRangeto 50 to keep the workflow consistent.