Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
56 lines (54 loc) · 1.75 KB
/
Copy patherrors_test.go
File metadata and controls
56 lines (54 loc) · 1.75 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
package codegraph
import (
"context"
"errors"
"fmt"
"testing"
)
func TestDirectoryBuildBudgetError(t *testing.T) {
ctx := context.Background()
doc := Document{Path: "a/b/data.txt", Content: []byte("data")}
full, report, err := Build(ctx, "directory-budget", []Document{doc}, Options{})
if err != nil {
t.Fatal(err)
}
evidence := 0
for _, edge := range full.Relations() {
evidence += len(edge.Evidence)
}
if _, _, err := Build(ctx, "directory-budget", []Document{doc}, Options{MaxNodes: report.Nodes, MaxRelations: report.Relations, MaxEvidence: evidence}); err != nil {
t.Fatal("exact directory budget rejected", err)
}
for _, tc := range []struct {
resource string
limit int
opts Options
}{
{"MaxNodes", report.Nodes - 1, Options{MaxNodes: report.Nodes - 1}},
{"MaxRelations", report.Relations - 1, Options{MaxRelations: report.Relations - 1}},
{"MaxEvidence", evidence - 1, Options{MaxEvidence: evidence - 1}},
} {
t.Run(tc.resource, func(t *testing.T) {
b, err := NewBuilder("directory-budget", tc.opts)
if err != nil {
t.Fatal(err)
}
previous := b.Result()
_, err = b.addDocumentsSync(ctx, doc)
wrapped := fmt.Errorf("build directory: %w", err)
var budget *BuildBudgetError
if !errors.Is(wrapped, ErrBuildBudget) || !errors.As(wrapped, &budget) {
t.Fatalf("budget contract unavailable: %v", wrapped)
}
if budget.Stage != "directory" || budget.Resource != tc.resource || budget.Used != tc.limit || budget.Adding != 1 || budget.Limit != tc.limit {
t.Fatalf("wrong budget details: %+v", budget)
}
if errors.Is(wrapped, ErrQueryBudget) {
t.Fatal("build error matched query budget")
}
if b.Result() != previous {
t.Fatal("failed directory publication replaced graph")
}
})
}
}