Consolidate import request ownership
This commit is contained in:
@@ -1268,7 +1268,8 @@ func TestImportTraversalEnforcesPrivateBudgets(t *testing.T) {
|
||||
{name: "aggregate nodes", limits: importLimits{depth: 8, sources: 8, bytes: maxTotalBytes, nodes: countInputNodes(main.document) + 1}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, _, diagnostics := loadImportedDocuments(File(mainPath), nil, main, nil, test.limits)
|
||||
request := testImportRequest(File(mainPath), nil, main, Path{}, nil, nil)
|
||||
_, _, diagnostics := testAcquireImportWithLimits(request, test.limits)
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != CodeImportLimitExceeded {
|
||||
t.Fatalf("budget diagnostics = %#v", diagnostics)
|
||||
}
|
||||
@@ -1278,7 +1279,8 @@ func TestImportTraversalEnforcesPrivateBudgets(t *testing.T) {
|
||||
writeImportFile(t, directory, "one.yml", "configkit: {imports: [{path: nested.yml}]}\n")
|
||||
writeImportFile(t, directory, "nested.yml", "settings: {nested: nested}\n")
|
||||
main = parseImportMain(t, mainPath)
|
||||
_, _, diagnostics := loadImportedDocuments(File(mainPath), nil, main, nil, importLimits{depth: 1, sources: 8, bytes: maxTotalBytes, nodes: maxDocumentNodes})
|
||||
request := testImportRequest(File(mainPath), nil, main, Path{}, nil, nil)
|
||||
_, _, diagnostics := testAcquireImportWithLimits(request, importLimits{depth: 1, sources: 8, bytes: maxTotalBytes, nodes: maxDocumentNodes})
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != CodeImportLimitExceeded {
|
||||
t.Fatalf("depth diagnostics = %#v", diagnostics)
|
||||
}
|
||||
@@ -1312,7 +1314,9 @@ func TestImportDepthBudgetCountsSelectedEdges(t *testing.T) {
|
||||
writeImportFile(t, directory, "parts/next.yml", "next: true\n")
|
||||
limits := defaultImportLimits()
|
||||
limits.depth = 1
|
||||
composed, sources, diagnostics := loadImportedDocuments(File(mainPath), nil, parseImportMain(t, mainPath), nil, limits)
|
||||
main := parseImportMain(t, mainPath)
|
||||
request := testImportRequest(File(mainPath), nil, main, Path{}, nil, nil)
|
||||
composed, sources, diagnostics := testAcquireImportWithLimits(request, limits)
|
||||
if test.code != "" {
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != test.code {
|
||||
t.Fatalf("diagnostics = %#v, want %s", diagnostics, test.code)
|
||||
@@ -1342,7 +1346,8 @@ func TestImportTraversalAcceptsExactPrivateBudgets(t *testing.T) {
|
||||
bytes: main.bytes + int64(len(data)),
|
||||
nodes: countInputNodes(main.document) + countInputNodes(imported.document),
|
||||
}
|
||||
composed, sources, diagnostics := loadImportedDocuments(File(mainPath), nil, main, nil, limits)
|
||||
request := testImportRequest(File(mainPath), nil, main, Path{}, nil, nil)
|
||||
composed, sources, diagnostics := testAcquireImportWithLimits(request, limits)
|
||||
if len(diagnostics) != 0 || composed == nil || len(sources) != 2 {
|
||||
t.Fatalf("exact-limit composition = (%#v, %#v, %#v)", composed, sources, diagnostics)
|
||||
}
|
||||
@@ -1401,6 +1406,32 @@ func parseImportMain(t *testing.T, filename string) parsedSource {
|
||||
return parsed
|
||||
}
|
||||
|
||||
func testImportRequest(source Source, context *FilesystemContext, main parsedSource, destination Path, rule *VersionRule, processing *sourceVersionProcessingResult) importAcquisitionRequest {
|
||||
return importAcquisitionRequest{
|
||||
input: inputAcquisitionRequest{
|
||||
input: loadInput{
|
||||
source: source, imports: true, filesystem: context,
|
||||
destination: destination.clone(), placementMode: main.source.placementMode,
|
||||
},
|
||||
role: sourceVersionMain, directiveContext: rootDirectiveContextImportsOnly,
|
||||
protectionRule: rule,
|
||||
},
|
||||
main: main, processing: processing,
|
||||
}
|
||||
}
|
||||
|
||||
func testAcquireImport(request importAcquisitionRequest, policy acquisitionPolicy, state *acquisitionState, tier *tierAcquisitionState) (*composedDocument, []SourceInfo, []Diagnostic) {
|
||||
return acquireImportedInput(request, &policy, state, tier)
|
||||
}
|
||||
|
||||
func testAcquireImportWithLimits(request importAcquisitionRequest, limits importLimits) (*composedDocument, []SourceInfo, []Diagnostic) {
|
||||
return testAcquireImport(request, acquisitionPolicy{importLimits: limits}, &acquisitionState{accounting: &importAccounting{}}, &tierAcquisitionState{})
|
||||
}
|
||||
|
||||
func testAcquireImportWithAccounting(request importAcquisitionRequest, limits importLimits, accounting *importAccounting) (*composedDocument, []SourceInfo, []Diagnostic) {
|
||||
return testAcquireImport(request, acquisitionPolicy{importLimits: limits}, &acquisitionState{accounting: accounting}, &tierAcquisitionState{})
|
||||
}
|
||||
|
||||
func parseImportSpecificationsYAML(t *testing.T, input string) []importDeclarationSpec {
|
||||
t.Helper()
|
||||
declarations, diagnostics := parseImportSpecificationYAML(input)
|
||||
|
||||
Reference in New Issue
Block a user