mirror of https://github.com/docker/buildx.git
Merge pull request #2176 from crazy-max/fix-builder-creation
driver(container): fix conditional statement for error handling
This commit is contained in:
commit
6b63e7e3de
|
@ -51,11 +51,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
|
|||
case k == "image":
|
||||
d.image = v
|
||||
case k == "memory":
|
||||
if err := d.memory.Set(v); err == nil {
|
||||
if err := d.memory.Set(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case k == "memory-swap":
|
||||
if err := d.memorySwap.Set(v); err == nil {
|
||||
if err := d.memorySwap.Set(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case k == "cpu-period":
|
||||
|
|
|
@ -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, imagetoolsTests...)
|
||||
tests = append(tests, versionTests...)
|
||||
tests = append(tests, createTests...)
|
||||
testIntegration(t, tests...)
|
||||
}
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue