mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	tests: add basic remote bake context test
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
		
							
								
								
									
										53
									
								
								tests/bake.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								tests/bake.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| package tests | ||||
|  | ||||
| import ( | ||||
| 	"path/filepath" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/containerd/continuity/fs/fstest" | ||||
| 	"github.com/docker/buildx/util/gitutil" | ||||
| 	"github.com/moby/buildkit/util/testutil/integration" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| ) | ||||
|  | ||||
| func bakeCmd(sb integration.Sandbox, dir string, args ...string) (string, error) { | ||||
| 	args = append([]string{"bake", "--progress=quiet"}, args...) | ||||
| 	cmd := buildxCmd(sb, args...) | ||||
| 	cmd.Dir = dir | ||||
| 	out, err := cmd.CombinedOutput() | ||||
| 	return string(out), err | ||||
| } | ||||
|  | ||||
| var bakeTests = []func(t *testing.T, sb integration.Sandbox){ | ||||
| 	testBakeRemote, | ||||
| } | ||||
|  | ||||
| func testBakeRemote(t *testing.T, sb integration.Sandbox) { | ||||
| 	bakefile := []byte(` | ||||
| target "default" { | ||||
| 	dockerfile-inline = <<EOT | ||||
| FROM scratch | ||||
| COPY foo /foo | ||||
| EOT | ||||
| } | ||||
| `) | ||||
| 	dir := tmpdir( | ||||
| 		t, | ||||
| 		fstest.CreateFile("docker-bake.hcl", bakefile, 0600), | ||||
| 		fstest.CreateFile("foo", []byte("foo"), 0600), | ||||
| 	) | ||||
| 	dirDest := t.TempDir() | ||||
|  | ||||
| 	git, err := gitutil.New(gitutil.WithWorkingDir(dir)) | ||||
| 	require.NoError(t, err) | ||||
|  | ||||
| 	gitutil.GitInit(git, t) | ||||
| 	gitutil.GitAdd(git, t, "docker-bake.hcl", "foo") | ||||
| 	gitutil.GitCommit(git, t, "initial commit") | ||||
| 	addr := gitutil.GitServeHTTP(git, t) | ||||
|  | ||||
| 	out, err := bakeCmd(sb, dir, addr, "--set", "*.output=type=local,dest="+dirDest) | ||||
| 	require.NoError(t, err, out) | ||||
|  | ||||
| 	require.FileExists(t, filepath.Join(dirDest, "foo")) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Justin Chadwell
					Justin Chadwell