Skip to content

Commit

Permalink
tests: Adding tests for hostname specifying for building
Browse files Browse the repository at this point in the history
Adding tests to for hostname specifying for image building

Cover: #1301
Signed-off-by: Lu Jingxiao <lujingxiao@huawei.com>
  • Loading branch information
jingxiaolu committed Oct 14, 2020
1 parent 5e7ae23 commit ec1131b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestIntegration(t *testing.T) {
testSSHMount,
testStdinClosed,
testHostnameLookup,
testHostnameSpecifying,
testPushByDigest,
testBasicInlineCacheImportExport,
testExportBusyboxLocal,
Expand Down Expand Up @@ -296,6 +297,28 @@ func testHostnameLookup(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
}

// moby/buildkit#1301
func testHostnameSpecifying(t *testing.T, sb integration.Sandbox) {
if sb.Rootless() {
t.SkipNow()
}

c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()

hostname := "testtest"
st := llb.Image("busybox:latest").With(llb.Hostname(hostname)).Run(llb.Shlexf("sh -c 'echo $HOSTNAME | grep %s'", hostname))

def, err := st.Marshal(context.TODO())
require.NoError(t, err)

_, err = c.Solve(context.TODO(), def, SolveOpt{
FrontendAttrs: map[string]string{"hostname": hostname},
}, nil)
require.NoError(t, err)
}

// moby/buildkit#614
func testStdinClosed(t *testing.T, sb integration.Sandbox) {
c, err := New(context.TODO(), sb.Address())
Expand Down
31 changes: 31 additions & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var allTests = []integration.Test{
testErrorsSourceMap,
testMultiArgs,
testFrontendSubrequests,
testDockefileCheckHostname,
}

var fileOpTests = []integration.Test{
Expand Down Expand Up @@ -4767,6 +4768,36 @@ COPY Dockerfile Dockerfile
require.True(t, called)
}

// moby/buildkit#1301
func testDockefileCheckHostname(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)
dockerfile := []byte(`
FROM busybox
RUN cat /etc/hosts | grep testtest
`)

dir, err := tmpdir(
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)

c, err := client.New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()

_, err = f.Solve(context.TODO(), c, client.SolveOpt{
FrontendAttrs: map[string]string{
"hostname": "testtest",
},
LocalDirs: map[string]string{
builder.DefaultLocalNameDockerfile: dir,
builder.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)
}

func tmpdir(appliers ...fstest.Applier) (string, error) {
tmpdir, err := ioutil.TempDir("", "buildkit-dockerfile")
if err != nil {
Expand Down

0 comments on commit ec1131b

Please sign in to comment.