|
5 | 5 | "fmt" |
6 | 6 | "log/slog" |
7 | 7 | "os" |
| 8 | + "os/exec" |
| 9 | + "path/filepath" |
8 | 10 | "slices" |
9 | 11 | "strings" |
10 | 12 | "testing" |
@@ -49,6 +51,19 @@ func installDependencies() bool { |
49 | 51 | return os.Getenv("E2E_SKIP_DEPENDENCIES") != "true" |
50 | 52 | } |
51 | 53 |
|
| 54 | +func makeKubectlPlugin() error { |
| 55 | + projectRoot := filepath.Join("..", "..") |
| 56 | + cmd := exec.Command("make", "kubectl-plugin") |
| 57 | + cmd.Dir = projectRoot |
| 58 | + cmd.Stdout = os.Stdout |
| 59 | + cmd.Stderr = os.Stderr |
| 60 | + |
| 61 | + if err := cmd.Run(); err != nil { |
| 62 | + return fmt.Errorf("failed to run make kubectl-plugin: %w", err) |
| 63 | + } |
| 64 | + return nil |
| 65 | +} |
| 66 | + |
52 | 67 | type helmChart struct { |
53 | 68 | name string |
54 | 69 | namespace string |
@@ -115,7 +130,11 @@ func getCharts() []helmChart { |
115 | 130 | } |
116 | 131 |
|
117 | 132 | func TestMain(m *testing.M) { |
| 133 | + // we build kubectl_runtime-enforcer binary to run plugin e2e tests |
| 134 | + makeKubectlPlugin() |
| 135 | + |
118 | 136 | charts := getCharts() |
| 137 | + |
119 | 138 | commonSetupFuncs := []env.Func{ |
120 | 139 | // we uninstall here as a defensive check but nothing should be left behind |
121 | 140 | uninstallHelmRepos(charts), |
@@ -226,11 +245,19 @@ func installHelmRepos(charts []helmChart) env.Func { |
226 | 245 | if strings.HasPrefix(chartPath, "/") { |
227 | 246 | // First we try to add the repo. |
228 | 247 | if err = manager.RunRepo(helm.WithArgs("add", chart.repoLocalName, chart.repoURL)); err != nil { |
229 | | - return ctx, fmt.Errorf("failed to add local repo '%s': %w", chart.repoLocalName, err) |
| 248 | + return ctx, fmt.Errorf( |
| 249 | + "failed to add local repo '%s': %w", |
| 250 | + chart.repoLocalName, |
| 251 | + err, |
| 252 | + ) |
230 | 253 | } |
231 | 254 | // Update the repo. |
232 | 255 | if err = manager.RunRepo(helm.WithArgs("update")); err != nil { |
233 | | - return ctx, fmt.Errorf("failed to update local repo '%s': %w", chart.repoLocalName, err) |
| 256 | + return ctx, fmt.Errorf( |
| 257 | + "failed to update local repo '%s': %w", |
| 258 | + chart.repoLocalName, |
| 259 | + err, |
| 260 | + ) |
234 | 261 | } |
235 | 262 | // The final chart path will be the name of repoLocalName + chartPath |
236 | 263 | chartPath = chart.repoLocalName + chartPath |
|
0 commit comments