| 112 | } |
| 113 | |
| 114 | func TestMetadataValidateMultipleErrors(t *testing.T) { |
| 115 | // Create metadata with multiple validation issues |
| 116 | metadata := Metadata{ |
| 117 | Name: "invalid name with spaces", // Invalid name |
| 118 | APIVersion: "", // Empty API version |
| 119 | Type: "", // Empty type |
| 120 | Runtime: "", // Empty runtime |
| 121 | Config: nil, // Missing config |
| 122 | RuntimeConfig: nil, // Missing runtime config |
| 123 | } |
| 124 | |
| 125 | err := metadata.Validate() |
| 126 | if err == nil { |
| 127 | t.Fatal("expected validation to fail with multiple errors") |
| 128 | } |
| 129 | |
| 130 | errStr := err.Error() |
| 131 | |
| 132 | // Check that all expected errors are present in the joined error |
| 133 | expectedErrors := []string{ |
| 134 | "invalid plugin name", |
| 135 | "empty APIVersion", |
| 136 | "empty type field", |
| 137 | "empty runtime field", |
| 138 | "missing config field", |
| 139 | "missing runtimeConfig field", |
| 140 | } |
| 141 | |
| 142 | for _, expectedErr := range expectedErrors { |
| 143 | if !strings.Contains(errStr, expectedErr) { |
| 144 | t.Errorf("expected error to contain %q, but got: %v", expectedErr, errStr) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // Verify that the error contains the correct number of error messages |
| 149 | errorCount := 0 |
| 150 | for _, expectedErr := range expectedErrors { |
| 151 | if strings.Contains(errStr, expectedErr) { |
| 152 | errorCount++ |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if errorCount < len(expectedErrors) { |
| 157 | t.Errorf("expected %d errors, but only found %d in: %v", len(expectedErrors), errorCount, errStr) |
| 158 | } |
| 159 | } |