Skip to content

Commit 3299611

Browse files
committed
Add test case for multiple image tags in build-docker-create
1 parent 13464b2 commit 3299611

File tree

1 file changed

+0
-81
lines changed

1 file changed

+0
-81
lines changed

docker_test.go

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import (
55
"fmt"
66
"github.com/docker/docker/api/types/mount"
77
"os"
8-
"os/exec"
98
"path"
109
"path/filepath"
11-
"strings"
1210
"testing"
1311
"time"
1412

@@ -289,85 +287,6 @@ func TestPushFatManifestImage(t *testing.T) {
289287
assert.True(t, totalResults > 1)
290288
}
291289

292-
func TestBuildDockerCreateWithMultipleTags(t *testing.T) {
293-
initContainerTest(t) // Initialize container test environments
294-
295-
var (
296-
repoName = tests.DockerLocalRepo
297-
buildName = "multiple-tags-build"
298-
buildNumber = "1"
299-
imageNameBase = tests.DockerImageName + "-multiple-tags"
300-
tag1 = "tag1"
301-
tag2 = "tag2"
302-
metadataFile = "build-metadata"
303-
)
304-
305-
// Create test image with multiple tags
306-
imageName1 := imageNameBase + ":" + tag1
307-
imageName2 := imageNameBase + ":" + tag2
308-
imageNames := []string{imageName1, imageName2}
309-
for _, imageName := range imageNames {
310-
imageTag, err := inttestutils.BuildTestImage(imageName, "", repoName, container.DockerClient)
311-
assert.NoError(t, err)
312-
defer commonTests.DeleteTestImage(t, imageTag, container.DockerClient)
313-
}
314-
315-
// Push images and generate build-metadata file
316-
err := PushTestImageWithMetadata(imageNames, repoName, metadataFile)
317-
assert.NoError(t, err, "Failed to push test image with metadata")
318-
319-
// Ensure metadata file exists
320-
_, err = os.Stat(metadataFile)
321-
assert.NoError(t, err, "Metadata file not found")
322-
323-
// Run 'build-docker-create' & publish the results to Artifactory
324-
err = artifactoryCli.Exec("build-docker-create", repoName, "--image-file="+metadataFile, "--build-name="+buildName, "--build-number="+buildNumber)
325-
assert.NoError(t, err, "Failed to execute build-docker-create")
326-
err = artifactoryCli.Exec("build-publish", buildName, buildNumber)
327-
assert.NoError(t, err, "Failed to publish build info")
328-
329-
// Validate the published build-info contains multiple tags
330-
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
331-
assert.NoError(t, err, "Error fetching published build-info")
332-
assert.True(t, found, "Build info was expected to be found")
333-
assert.GreaterOrEqual(t, len(publishedBuildInfo.BuildInfo.Modules), 1, "Expected at least one module in build-info")
334-
335-
// Verify that both tags are recorded in the build-info
336-
moduleFound := false
337-
for _, module := range publishedBuildInfo.BuildInfo.Modules {
338-
if len(module.Artifacts) > 0 && strings.Contains(module.Artifacts[0].Name, imageNameBase) {
339-
tags := []string{tag1, tag2}
340-
for _, tag := range tags {
341-
imageTag := path.Join(repoName, imageNameBase+":"+tag) + "/"
342-
validateContainerBuild(buildName, buildNumber, imageTag, imageNameBase+":"+tag, 7, 5, 7, t)
343-
}
344-
moduleFound = true
345-
break
346-
}
347-
}
348-
assert.True(t, moduleFound, "Expected module not found in build-info")
349-
}
350-
351-
func PushTestImageWithMetadata(imageNames []string, repo, metadataFile string) error {
352-
args := []string{"buildx", "build", "--platform", "linux/amd64,linux/arm64", "--push", "--metadata-file", metadataFile}
353-
for _, imageName := range imageNames {
354-
args = append(args, "-t", imageName)
355-
}
356-
args = append(args, ".")
357-
358-
// Debug log for the constructed command
359-
fmt.Printf("Running command: docker %s\n", strings.Join(args, " "))
360-
361-
cmd := exec.Command("docker", args...)
362-
stdoutStderr, err := cmd.CombinedOutput()
363-
fmt.Printf("Output: %s\n", stdoutStderr) // Output log
364-
365-
if err != nil {
366-
return fmt.Errorf("failed to run buildx command: %s; output: %s", err, stdoutStderr)
367-
}
368-
return nil
369-
}
370-
371290
func TestContainerPushBuildNameNumberFromEnv(t *testing.T) {
372291
containerManagers := initContainerTest(t)
373292
for _, containerManager := range containerManagers {

0 commit comments

Comments
 (0)