mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
driver(container): fix conditional statement for error handling
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> (cherry picked from commit 57d737a13c9e7484753d796407582a9a3997d7d2)
This commit is contained in:
parent
b68ee824c6
commit
8fb1163577
@ -51,11 +51,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
|||||||
case k == "image":
|
case k == "image":
|
||||||
d.image = v
|
d.image = v
|
||||||
case k == "memory":
|
case k == "memory":
|
||||||
if err := d.memory.Set(v); err == nil {
|
if err := d.memory.Set(v); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case k == "memory-swap":
|
case k == "memory-swap":
|
||||||
if err := d.memorySwap.Set(v); err == nil {
|
if err := d.memorySwap.Set(v); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case k == "cpu-period":
|
case k == "cpu-period":
|
||||||
|
39
tests/create.go
Normal file
39
tests/create.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/moby/buildkit/util/testutil/integration"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
|
||||||
|
opts = append([]cmdOpt{withArgs("create")}, opts...)
|
||||||
|
cmd := buildxCmd(sb, opts...)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
return string(out), err
|
||||||
|
}
|
||||||
|
|
||||||
|
var createTests = []func(t *testing.T, sb integration.Sandbox){
|
||||||
|
testCreateMemoryLimit,
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
|
||||||
|
if sb.Name() != "docker-container" {
|
||||||
|
t.Skip("only testing for docker-container driver")
|
||||||
|
}
|
||||||
|
|
||||||
|
var builderName string
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if builderName == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out, err := rmCmd(sb, withArgs(builderName))
|
||||||
|
require.NoError(t, err, out)
|
||||||
|
})
|
||||||
|
|
||||||
|
out, err := createCmd(sb, withArgs("--driver", "docker-container", "--driver-opt", "network=host", "--driver-opt", "memory=1g"))
|
||||||
|
require.NoError(t, err, out)
|
||||||
|
builderName = strings.TrimSpace(out)
|
||||||
|
}
|
@ -27,6 +27,7 @@ func TestIntegration(t *testing.T) {
|
|||||||
tests = append(tests, lsTests...)
|
tests = append(tests, lsTests...)
|
||||||
tests = append(tests, imagetoolsTests...)
|
tests = append(tests, imagetoolsTests...)
|
||||||
tests = append(tests, versionTests...)
|
tests = append(tests, versionTests...)
|
||||||
|
tests = append(tests, createTests...)
|
||||||
testIntegration(t, tests...)
|
testIntegration(t, tests...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
tests/rm.go
Normal file
12
tests/rm.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/moby/buildkit/util/testutil/integration"
|
||||||
|
)
|
||||||
|
|
||||||
|
func rmCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
|
||||||
|
opts = append([]cmdOpt{withArgs("rm")}, opts...)
|
||||||
|
cmd := buildxCmd(sb, opts...)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
return string(out), err
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user