Merge pull request #2341 from crazy-max/tests-refactor-worker-handling

tests: refactor worker handling in sandbox
This commit is contained in:
Tõnis Tiigi 2024-03-15 12:53:27 -07:00 committed by GitHub
commit 324afe60ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 67 additions and 47 deletions

View File

@ -641,8 +641,8 @@ target "default" {
}
func testBakeMultiExporters(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
registry, err := sb.NewRegistry()
@ -722,8 +722,8 @@ target "default" {
}
func testBakeLoadPush(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
registry, err := sb.NewRegistry()

View File

@ -125,7 +125,7 @@ func testBuildRegistryExportAttestations(t *testing.T, sb integration.Sandbox) {
target := registry + "/buildx/registry:latest"
out, err := buildCmd(sb, withArgs(fmt.Sprintf("--output=type=image,name=%s,push=true", target), "--provenance=true", dir))
if sb.Name() == "docker" {
if isMobyWorker(sb) {
require.Error(t, err)
require.Contains(t, out, "Attestation is not supported")
return
@ -200,7 +200,7 @@ func testImageIDOutput(t *testing.T, sb integration.Sandbox) {
func testBuildMobyFromLocalImage(t *testing.T, sb integration.Sandbox) {
if !isDockerWorker(sb) {
t.Skip("skipping test for non-docker workers")
t.Skip("only testing with docker workers")
}
// pull image
@ -290,7 +290,7 @@ RUN exit 1`)
func testBuildProgress(t *testing.T, sb integration.Sandbox) {
dir := createTestProject(t)
driver, _, _ := strings.Cut(sb.Name(), "+")
sbDriver, _ := driverName(sb.Name())
name := sb.Address()
// progress=tty
@ -301,7 +301,7 @@ func testBuildProgress(t *testing.T, sb integration.Sandbox) {
io.Copy(buf, f)
ttyOutput := buf.String()
require.Contains(t, ttyOutput, "[+] Building")
require.Contains(t, ttyOutput, fmt.Sprintf("%s:%s", driver, name))
require.Contains(t, ttyOutput, fmt.Sprintf("%s:%s", sbDriver, name))
require.Contains(t, ttyOutput, "=> [internal] load build definition from Dockerfile")
require.Contains(t, ttyOutput, "=> [base 1/3] FROM docker.io/library/busybox:latest")
@ -309,13 +309,13 @@ func testBuildProgress(t *testing.T, sb integration.Sandbox) {
cmd = buildxCmd(sb, withArgs("build", "--progress=plain", "--output=type=cacheonly", dir))
plainOutput, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Contains(t, string(plainOutput), fmt.Sprintf(`#0 building with "%s" instance using %s driver`, name, driver))
require.Contains(t, string(plainOutput), fmt.Sprintf(`#0 building with "%s" instance using %s driver`, name, sbDriver))
require.Contains(t, string(plainOutput), "[internal] load build definition from Dockerfile")
require.Contains(t, string(plainOutput), "[base 1/3] FROM docker.io/library/busybox:latest")
}
func testBuildAnnotations(t *testing.T, sb integration.Sandbox) {
if sb.Name() == "docker" {
if isMobyWorker(sb) {
t.Skip("annotations not supported on docker worker")
}
@ -374,8 +374,8 @@ func testBuildLabelNoKey(t *testing.T, sb integration.Sandbox) {
}
func testBuildCacheExportNotSupported(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isMobyWorker(sb) {
t.Skip("only testing with docker worker")
}
dir := createTestProject(t)
@ -386,8 +386,8 @@ func testBuildCacheExportNotSupported(t *testing.T, sb integration.Sandbox) {
}
func testBuildOCIExportNotSupported(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isMobyWorker(sb) {
t.Skip("only testing with docker worker")
}
dir := createTestProject(t)
@ -398,8 +398,8 @@ func testBuildOCIExportNotSupported(t *testing.T, sb integration.Sandbox) {
}
func testBuildMultiPlatformNotSupported(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isMobyWorker(sb) {
t.Skip("only testing with docker worker")
}
dir := createTestProject(t)
@ -426,8 +426,8 @@ RUN ping -c 1 buildx.host-gateway-ip.local
}
func testBuildNetworkModeBridge(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderName string
@ -546,8 +546,8 @@ func testBuildRef(t *testing.T, sb integration.Sandbox) {
}
func testBuildMultiExporters(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
registry, err := sb.NewRegistry()
@ -614,8 +614,8 @@ func testBuildMultiExporters(t *testing.T, sb integration.Sandbox) {
}
func testBuildLoadPush(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
registry, err := sb.NewRegistry()

View File

@ -26,8 +26,8 @@ var createTests = []func(t *testing.T, sb integration.Sandbox){
}
func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderName string
@ -45,8 +45,8 @@ func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
}
func testCreateRestartAlways(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderName string

View File

@ -22,8 +22,8 @@ var imagetoolsTests = []func(t *testing.T, sb integration.Sandbox){
}
func testImagetoolsCopyManifest(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("imagetools tests are not driver specific and only run on docker-container")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker, imagetools only runs on docker-container")
}
dir := createDockerfile(t)
@ -81,8 +81,8 @@ func testImagetoolsCopyManifest(t *testing.T, sb integration.Sandbox) {
}
func testImagetoolsCopyIndex(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("imagetools tests are not driver specific and only run on docker-container")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker, imagetools only runs on docker-container")
}
dir := createDockerfile(t)
@ -130,8 +130,8 @@ func testImagetoolsCopyIndex(t *testing.T, sb integration.Sandbox) {
}
func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("imagetools tests are not driver specific and only run on docker-container")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker, imagetools only runs on docker-container")
}
dir := createDockerfile(t)
@ -181,8 +181,8 @@ func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) {
}
func testImagetoolsAnnotation(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("imagetools tests are not driver specific and only run on docker-container")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker, imagetools only runs on docker-container")
}
dir := createDockerfile(t)

View File

@ -41,7 +41,7 @@ func testInspect(t *testing.T, sb integration.Sandbox) {
}
require.Equal(t, sb.Address(), name)
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
sbDriver, _ := driverName(sb.Name())
require.Equal(t, sbDriver, driver)
if isDockerWorker(sb) {
require.NotEmpty(t, hostGatewayIP, "host-gateway-ip worker label should be set with docker driver")
@ -51,8 +51,8 @@ func testInspect(t *testing.T, sb integration.Sandbox) {
}
func testInspectBuildkitdFlags(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderName string
@ -81,8 +81,8 @@ func testInspectBuildkitdFlags(t *testing.T, sb integration.Sandbox) {
}
func testInspectNetworkHostEntitlement(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderName string

View File

@ -71,7 +71,27 @@ func dockerCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
return cmd
}
func isDockerWorker(sb integration.Sandbox) bool {
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
return sbDriver == "docker"
func isMobyWorker(sb integration.Sandbox) bool {
name, hasFeature := driverName(sb.Name())
return name == "docker" && !hasFeature
}
func isDockerWorker(sb integration.Sandbox) bool {
name, _ := driverName(sb.Name())
return name == "docker"
}
func isDockerContainerWorker(sb integration.Sandbox) bool {
name, _ := driverName(sb.Name())
return name == "docker-container"
}
func driverName(sbName string) (string, bool) {
name := sbName
var hasFeature bool
if b, _, ok := strings.Cut(name, "+"); ok {
name = b
hasFeature = true
}
return name, hasFeature
}

View File

@ -34,7 +34,7 @@ func testLs(t *testing.T, sb integration.Sandbox) {
},
}
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
sbDriver, _ := driverName(sb.Name())
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {

View File

@ -21,8 +21,8 @@ var rmTests = []func(t *testing.T, sb integration.Sandbox){
}
func testRm(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
out, err := rmCmd(sb, withArgs("default"))
@ -40,8 +40,8 @@ func testRm(t *testing.T, sb integration.Sandbox) {
}
func testRmMulti(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
if !isDockerContainerWorker(sb) {
t.Skip("only testing with docker-container worker")
}
var builderNames []string