Skip to content

Commit

Permalink
integration: add test for hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkarp committed Jun 20, 2022
1 parent 6136621 commit 027fcd7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/integration/inside_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build inside
// +build inside

package integration
Expand Down Expand Up @@ -33,3 +34,9 @@ func TestNullMount(t *testing.T) {
err = ioutil.WriteFile("/volume/world.txt", []byte("output file"), 0644)
assert.NoError(t, err, "cannot write world.txt")
}

func TestHostname(t *testing.T) {
hostname, err := os.Hostname()
assert.NoError(t, err, "failed to retrieve hostname")
fmt.Println(hostname)
}
31 changes: 29 additions & 2 deletions test/integration/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func TestCreateDelete(t *testing.T) {
Env: []string{"one=two", "three=four", "five"},
},
},
// hostname
{
Hostname: "foo.bar.example.com",
Process: &runtimespec.Process{},
},
}

for i, tc := range tests {
Expand Down Expand Up @@ -138,7 +143,7 @@ func TestJailEnv(t *testing.T) {
Env: env,
}

stdout, stderr, err := runSimpleExitingJail(t, "integ-test-hello", spec, 500*time.Millisecond)
stdout, stderr, err := runSimpleExitingJail(t, "integ-test-env", spec, 500*time.Millisecond)
assert.NoError(t, err)
assertJailPass(t, stdout, stderr)
lines := strings.Split(string(stdout), "\n")
Expand Down Expand Up @@ -167,7 +172,7 @@ func TestJailNullMount(t *testing.T) {
Type: "nullfs",
Source: volume,
}}
stdout, stderr, err := runSimpleExitingJail(t, "integ-test-hello", spec, 500*time.Millisecond)
stdout, stderr, err := runSimpleExitingJail(t, "integ-test-null", spec, 500*time.Millisecond)
assert.NoError(t, err)
assertJailPass(t, stdout, stderr)
output, err := ioutil.ReadFile(filepath.Join(volume, "world.txt"))
Expand All @@ -178,6 +183,28 @@ func TestJailNullMount(t *testing.T) {
}
}

func TestJailHostname(t *testing.T) {
hostname := fmt.Sprintf("%s.example", t.Name())

spec, cleanup := setupSimpleExitingJail(t)
defer cleanup()

spec.Hostname = hostname
spec.Process = &runtimespec.Process{
Args: []string{"/integ-inside", "-test.run", "TestHostname"},
}

stdout, stderr, err := runSimpleExitingJail(t, "integ-test-hostname", spec, 500*time.Millisecond)
assert.NoError(t, err)
assertJailPass(t, stdout, stderr)
lines := strings.Split(string(stdout), "\n")
assert.Len(t, lines, 3, "should be exactly 3 lines of output")
assert.Equal(t, hostname, lines[0], "hostname should match")
if t.Failed() {
t.Log("STDOUT:", string(stdout))
}
}

func setupSimpleExitingJail(t *testing.T) (runtimespec.Spec, func()) {
root, err := ioutil.TempDir("", "runj-integ-test-"+t.Name())
require.NoError(t, err, "create root")
Expand Down

0 comments on commit 027fcd7

Please sign in to comment.