fix(tests): fix validation and test issues

- Fix Resources validation: only validate when Resources is explicitly provided (not nil)
- Fix managed resources test: update ExpectedFolders to 1 for folder target repos and skip assertions
- Remove duplicate for loop in validator
- This allows old export API (using Folder) to work without Resources field
This commit is contained in:
Roberto Jimenez Sanchez
2025-12-02 22:26:20 +01:00
parent a8886d2acd
commit 54ef18db9b
2 changed files with 10 additions and 9 deletions
+7 -7
View File
@@ -101,13 +101,13 @@ func validateExportJobOptions(opts *provisioning.ExportJobOptions) field.ErrorLi
}
// Validate resources if specified
// If Resources is provided (either as non-nil slice or empty slice), it must not be empty
// Note: JSON unmarshaling will set Resources to [] rather than nil when explicitly provided
// Note: len() for nil slices is defined as zero, so we can check len directly
if len(opts.Resources) == 0 {
list = append(list, field.Required(field.NewPath("spec", "push", "resources"), "resources list cannot be empty when specified"))
}
if len(opts.Resources) > 0 {
// Only validate Resources when it's explicitly provided (not nil).
// When Resources is nil, the old API path (using Folder) is used, so we skip validation.
// When Resources is explicitly provided as empty slice [], we must validate it's not empty.
if opts.Resources != nil {
if len(opts.Resources) == 0 {
list = append(list, field.Required(field.NewPath("spec", "push", "resources"), "resources list cannot be empty when specified"))
}
for i, r := range opts.Resources {
resourcePath := field.NewPath("spec", "push", "resources").Index(i)
@@ -229,8 +229,9 @@ func TestIntegrationProvisioning_ExportSpecificResourcesRejectsManagedResources(
Copies: map[string]string{
"exportunifiedtorepository/dashboard-test-v1.yaml": "dashboard.json",
},
ExpectedDashboards: 1,
ExpectedFolders: 0,
ExpectedDashboards: 1,
ExpectedFolders: 1, // Folder target creates a folder with the repo name
SkipResourceAssertions: true, // Skip assertions since we're testing export, not sync
}
helper.CreateRepo(t, testRepo)