TestWritePredicate_AbsolutePath tests WritePredicate with absolute path handling
(t *testing.T)
| 223 | |
| 224 | // TestWritePredicate_AbsolutePath tests WritePredicate with absolute path handling |
| 225 | func TestWritePredicate_AbsolutePath(t *testing.T) { |
| 226 | // Set up test filesystem |
| 227 | fs := afero.NewMemMapFs() |
| 228 | |
| 229 | // Create test predicate |
| 230 | pred := &Predicate{ |
| 231 | Policy: ecapi.EnterpriseContractPolicySpec{ |
| 232 | Name: "test-policy", |
| 233 | }, |
| 234 | ImageRefs: []string{"test-image:tag"}, |
| 235 | Timestamp: "2024-03-21T12:00:00Z", |
| 236 | Status: "passed", |
| 237 | Verifier: "conforma", |
| 238 | Summary: VSASummary{ |
| 239 | Component: ComponentSummary{ |
| 240 | Name: "test-component", |
| 241 | ContainerImage: "test-image:tag", |
| 242 | Source: nil, |
| 243 | }, |
| 244 | }, |
| 245 | } |
| 246 | |
| 247 | // Test with absolute path |
| 248 | writer := Writer{ |
| 249 | FS: fs, |
| 250 | TempDirPrefix: "/tmp/test-vsa", |
| 251 | FilePerm: 0o600, |
| 252 | } |
| 253 | |
| 254 | // Write VSA |
| 255 | vsaPath, err := writer.WritePredicate(pred) |
| 256 | require.NoError(t, err) |
| 257 | |
| 258 | // Verify the directory was created and file is in the correct location |
| 259 | assert.Contains(t, vsaPath, "/tmp/test-vsa/vsa-test-component.json") |
| 260 | |
| 261 | // Verify the directory exists |
| 262 | exists, err := afero.DirExists(fs, "/tmp/test-vsa") |
| 263 | assert.NoError(t, err) |
| 264 | assert.True(t, exists, "Output directory should be created") |
| 265 | |
| 266 | // Read and verify contents |
| 267 | data, err := afero.ReadFile(fs, vsaPath) |
| 268 | require.NoError(t, err) |
| 269 | |
| 270 | var output Predicate |
| 271 | err = json.Unmarshal(data, &output) |
| 272 | require.NoError(t, err) |
| 273 | |
| 274 | // Verify fields |
| 275 | assert.Equal(t, pred.Policy, output.Policy) |
| 276 | assert.Equal(t, pred.ImageRefs, output.ImageRefs) |
| 277 | assert.Equal(t, pred.Timestamp, output.Timestamp) |
| 278 | assert.Equal(t, pred.Status, output.Status) |
| 279 | assert.Equal(t, pred.Verifier, output.Verifier) |
| 280 | assert.Equal(t, pred.Summary, output.Summary) |
| 281 | } |
| 282 |
nothing calls this directly
no test coverage detected