tests: create remote with container helper

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-03-09 17:02:52 +01:00
parent 8f576e5790
commit b1490ed5ce
5 changed files with 70 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"io"
"net"
"strings"
"github.com/docker/buildx/store"
"github.com/docker/buildx/util/progress"
@ -67,6 +68,19 @@ type Driver interface {
Config() InitConfig
}
const builderNamePrefix = "buildx_buildkit_"
func BuilderName(name string) string {
return builderNamePrefix + name
}
func ParseBuilderName(name string) (string, error) {
if !strings.HasPrefix(name, builderNamePrefix) {
return "", errors.Errorf("invalid builder name %q, must have %q prefix", name, builderNamePrefix)
}
return strings.TrimPrefix(name, builderNamePrefix), nil
}
func Boot(ctx, clientContext context.Context, d *DriverHandle, pw progress.Writer) (*client.Client, error) {
try := 0
for {

View File

@ -244,10 +244,10 @@ func (f *factory) AllowsInstances() bool {
// eg. "buildx_buildkit_loving_mendeleev0" -> "loving-mendeleev0"
func buildxNameToDeploymentName(bx string) (string, error) {
// TODO: commands.util.go should not pass "buildx_buildkit_" prefix to drivers
if !strings.HasPrefix(bx, "buildx_buildkit_") {
return "", errors.Errorf("expected a string with \"buildx_buildkit_\", got %q", bx)
s, err := driver.ParseBuilderName(bx)
if err != nil {
return "", err
}
s := strings.TrimPrefix(bx, "buildx_buildkit_")
s = strings.ReplaceAll(s, "_", "-")
return s, nil
}

View File

@ -29,7 +29,7 @@ func TestFactory_processDriverOpts(t *testing.T) {
}
cfg := driver.InitConfig{
Name: "buildx_buildkit_test",
Name: driver.BuilderName("test"),
KubeClientConfig: &kcc,
}
f := factory{}