MCPcopy Create free account
hub / github.com/conforma/cli / TestWorker

Function TestWorker

cmd/validate/vsa_test.go:1349–1403  ·  view source on GitHub ↗

TestWorker tests the worker goroutine functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

1347
1348// TestWorker tests the worker goroutine functionality
1349func TestWorker(t *testing.T) {
1350 ctx := context.Background()
1351
1352 // Create test data
1353 data := &validateVSAData{
1354 vsaIdentifier: "test-vsa-id",
1355 policyConfig: "test-policy.yaml",
1356 }
1357
1358 // Create test components
1359 components := []app.SnapshotComponent{
1360 {
1361 Name: "component-1",
1362 ContainerImage: "nginx:latest",
1363 },
1364 {
1365 Name: "component-2",
1366 ContainerImage: "redis:latest",
1367 },
1368 }
1369
1370 // Create channels
1371 jobs := make(chan app.SnapshotComponent, len(components))
1372 results := make(chan vsa.ComponentResult, len(components))
1373
1374 // Start worker
1375 go worker(jobs, results, ctx, data)
1376
1377 // Send jobs
1378 for _, component := range components {
1379 jobs <- component
1380 }
1381 close(jobs)
1382
1383 // Collect results
1384 var receivedResults []vsa.ComponentResult
1385 for i := 0; i < len(components); i++ {
1386 select {
1387 case result := <-results:
1388 receivedResults = append(receivedResults, result)
1389 case <-time.After(5 * time.Second):
1390 t.Fatal("Timeout waiting for worker results")
1391 }
1392 }
1393
1394 // Verify results
1395 assert.Len(t, receivedResults, len(components))
1396
1397 for i, result := range receivedResults {
1398 assert.Equal(t, components[i].Name, result.ComponentName)
1399 assert.Equal(t, components[i].ContainerImage, result.ImageRef)
1400 // Note: The actual validation may fail due to missing retrievers in test environment
1401 // but we're testing the worker structure and result handling
1402 }
1403}
1404
1405// TestValidateSnapshotVSAs_Comprehensive tests the full snapshot processing functionality
1406func TestValidateSnapshotVSAs_Comprehensive(t *testing.T) {

Callers

nothing calls this directly

Calls 1

workerFunction · 0.85

Tested by

no test coverage detected