(t *testing.T)
| 89 | } |
| 90 | |
| 91 | func TestValidateDockerImage(t *testing.T) { |
| 92 | // Skip if docker is not available |
| 93 | if _, err := exec.LookPath("docker"); err != nil { |
| 94 | t.Skip("docker not available, skipping test") |
| 95 | } |
| 96 | // Also check if Docker daemon is running (not just if binary exists) |
| 97 | if !isDockerDaemonRunning() { |
| 98 | t.Skip("docker daemon not running, skipping test") |
| 99 | } |
| 100 | |
| 101 | tests := []struct { |
| 102 | name string |
| 103 | image string |
| 104 | expectError bool |
| 105 | }{ |
| 106 | { |
| 107 | name: "valid image - alpine", |
| 108 | image: "alpine:latest", |
| 109 | expectError: false, |
| 110 | }, |
| 111 | { |
| 112 | name: "invalid image", |
| 113 | image: "nonexistent-image-12345:nonexistent", |
| 114 | expectError: true, |
| 115 | }, |
| 116 | } |
| 117 | |
| 118 | for _, tt := range tests { |
| 119 | t.Run(tt.name, func(t *testing.T) { |
| 120 | err := validateDockerImage(tt.image, false, false) |
| 121 | |
| 122 | if tt.expectError && err == nil { |
| 123 | t.Error("expected error but got none") |
| 124 | } |
| 125 | if !tt.expectError && err != nil { |
| 126 | t.Errorf("unexpected error: %v", err) |
| 127 | } |
| 128 | }) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestExtractNpxPackages(t *testing.T) { |
| 133 | tests := []struct { |
nothing calls this directly
no test coverage detected