initializePlugins copies the necessary plugin files to the temporary config directory for the test.
(t testing.TB, configDir string)
| 135 | // initializePlugins copies the necessary plugin files to the temporary config |
| 136 | // directory for the test. |
| 137 | func initializePlugins(t testing.TB, configDir string) { |
| 138 | t.Cleanup(func() { |
| 139 | if t.Failed() { |
| 140 | if conf, err := os.ReadFile(filepath.Join(configDir, "config.json")); err == nil { |
| 141 | t.Logf("Config: %s\n", string(conf)) |
| 142 | } |
| 143 | t.Log("Contents of config dir:") |
| 144 | for _, p := range dirContents(configDir) { |
| 145 | t.Logf(" - %s", p) |
| 146 | } |
| 147 | } |
| 148 | }) |
| 149 | |
| 150 | assert.NilError(t, os.MkdirAll(filepath.Join(configDir, "cli-plugins"), 0o755), |
| 151 | "Failed to create cli-plugins directory") |
| 152 | composePlugin, err := findExecutable(DockerComposeExecutableName) |
| 153 | if errors.Is(err, fs.ErrNotExist) { |
| 154 | t.Logf("WARNING: docker-compose cli-plugin not found") |
| 155 | } |
| 156 | |
| 157 | if err == nil { |
| 158 | CopyFile(t, composePlugin, filepath.Join(configDir, "cli-plugins", DockerComposeExecutableName)) |
| 159 | buildxPlugin, err := findPluginExecutable(DockerBuildxExecutableName) |
| 160 | if err != nil { |
| 161 | t.Logf("WARNING: docker-buildx cli-plugin not found, using default buildx installation.") |
| 162 | } else { |
| 163 | CopyFile(t, buildxPlugin, filepath.Join(configDir, "cli-plugins", DockerBuildxExecutableName)) |
| 164 | } |
| 165 | // We don't need a functional scan plugin, but a valid plugin binary |
| 166 | CopyFile(t, composePlugin, filepath.Join(configDir, "cli-plugins", DockerScanExecutableName)) |
| 167 | |
| 168 | modelPlugin, err := findPluginExecutable(DockerModelExecutableName) |
| 169 | if err != nil { |
| 170 | t.Logf("WARNING: docker-model cli-plugin not found") |
| 171 | } else { |
| 172 | CopyFile(t, modelPlugin, filepath.Join(configDir, "cli-plugins", DockerModelExecutableName)) |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func initializeContextDir(t testing.TB, configDir string) { |
| 178 | dockerUserDir := ".docker/contexts" |
no test coverage detected