Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tests/rkt_ace_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"os"
"testing"

"github.com/coreos/rkt/tests/testutils"
)

var expectedResults = []string{
Expand All @@ -28,10 +30,10 @@ var expectedResults = []string{
}

func TestAceValidator(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

if err := ctx.launchMDS(); err != nil {
if err := ctx.LaunchMDS(); err != nil {
t.Fatalf("Cannot launch metadata service: %v", err)
}

Expand All @@ -46,7 +48,7 @@ func TestAceValidator(t *testing.T) {

rktArgs := fmt.Sprintf("--debug --insecure-skip-verify run --mds-register --volume database,kind=empty %s %s",
aceMain, aceSidekick)
rktCmd := fmt.Sprintf("%s %s", ctx.cmd(), rktArgs)
rktCmd := fmt.Sprintf("%s %s", ctx.Cmd(), rktArgs)

child := spawnOrFail(t, rktCmd)
defer waitOrFail(t, child, true)
Expand Down
19 changes: 10 additions & 9 deletions tests/rkt_app_isolator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/coreos/rkt/common/cgroup"
"github.com/coreos/rkt/tests/testutils"
)

const (
Expand Down Expand Up @@ -59,15 +60,15 @@ func TestAppIsolatorMemory(t *testing.T) {
t.Skip("Memory isolator not supported.")
}

ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

t.Logf("Running test: %v", memoryTest.testName)

aciFileName := patchTestACI("rkt-inspect-isolators.aci", memoryTest.aciBuildArgs...)
defer os.Remove(aciFileName)

rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.cmd(), aciFileName)
rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.Cmd(), aciFileName)
expectedLine := "Memory Limit: " + strconv.Itoa(maxMemoryUsage)
runRktAndCheckOutput(t, rktCmd, expectedLine, false)
}
Expand All @@ -78,29 +79,29 @@ func TestAppIsolatorCPU(t *testing.T) {
t.Skip("CPU isolator not supported.")
}

ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

t.Logf("Running test: %v", cpuTest.testName)

aciFileName := patchTestACI("rkt-inspect-isolators.aci", cpuTest.aciBuildArgs...)
defer os.Remove(aciFileName)

rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.cmd(), aciFileName)
rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.Cmd(), aciFileName)
expectedLine := "CPU Quota: " + strconv.Itoa(CPUQuota)
runRktAndCheckOutput(t, rktCmd, expectedLine, false)
}

func TestCgroups(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

t.Logf("Running test: %v", cgroupsTest.testName)

aciFileName := patchTestACI("rkt-inspect-isolators.aci", cgroupsTest.aciBuildArgs...)
defer os.Remove(aciFileName)

rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.cmd(), aciFileName)
rktCmd := fmt.Sprintf("%s --insecure-skip-verify run --mds-register=false %s", ctx.Cmd(), aciFileName)
expectedLine := "check-cgroups: SUCCESS"
runRktAndCheckOutput(t, rktCmd, expectedLine, false)
}
55 changes: 28 additions & 27 deletions tests/rkt_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"testing"

taas "github.com/coreos/rkt/tests/test-auth-server/aci"
"github.com/coreos/rkt/tests/testutils"
)

func TestAuthSanity(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
server := runServer(t, taas.None)
defer server.Close()
expectedRunRkt(ctx, t, server.URL, "sanity", authSuccessfulDownload)
Expand Down Expand Up @@ -73,27 +74,27 @@ func TestAuthOauth(t *testing.T) {
func testAuthGeneric(t *testing.T, auth taas.Type, tests []genericAuthTest) {
server := runServer(t, auth)
defer server.Close()
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
for _, tt := range tests {
switch tt.confDir {
case authConfDirNone:
// no config to write
case authConfDirLocal:
writeConfig(t, ctx.localDir(), "test.json", server.Conf)
writeConfig(t, ctx.LocalDir(), "test.json", server.Conf)
case authConfDirSystem:
writeConfig(t, ctx.systemDir(), "test.json", server.Conf)
writeConfig(t, ctx.SystemDir(), "test.json", server.Conf)
default:
panic("Wrong config directory")
}
expectedRunRkt(ctx, t, server.URL, tt.name, tt.expectedLine)
ctx.reset()
ctx.Reset()
}
}

func TestAuthOverride(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
server := runServer(t, taas.Oauth)
defer server.Close()
tests := []struct {
Expand All @@ -107,11 +108,11 @@ func TestAuthOverride(t *testing.T) {
{getInvalidOAuthConfig(server.Conf), server.Conf, "invalid-system-valid-local", authFailedDownload, authSuccessfulDownload},
}
for _, tt := range tests {
writeConfig(t, ctx.systemDir(), "test.json", tt.systemConfig)
writeConfig(t, ctx.SystemDir(), "test.json", tt.systemConfig)
expectedRunRkt(ctx, t, server.URL, tt.name+"-1", tt.resultBeforeOverride)
writeConfig(t, ctx.localDir(), "test.json", tt.localConfig)
writeConfig(t, ctx.LocalDir(), "test.json", tt.localConfig)
expectedRunRkt(ctx, t, server.URL, tt.name+"-2", tt.resultAfterOverride)
ctx.reset()
ctx.Reset()
}
}

Expand All @@ -123,28 +124,28 @@ func TestAuthIgnore(t *testing.T) {
}

func testAuthIgnoreBogusFiles(t *testing.T, server *taas.Server) {
ctx := newRktRunCtx()
defer ctx.cleanup()
writeConfig(t, ctx.systemDir(), "README", "This is system config")
writeConfig(t, ctx.localDir(), "README", "This is local config")
writeConfig(t, ctx.systemDir(), "test.notjson", server.Conf)
writeConfig(t, ctx.localDir(), "test.notjson", server.Conf)
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
writeConfig(t, ctx.SystemDir(), "README", "This is system config")
writeConfig(t, ctx.LocalDir(), "README", "This is local config")
writeConfig(t, ctx.SystemDir(), "test.notjson", server.Conf)
writeConfig(t, ctx.LocalDir(), "test.notjson", server.Conf)
expectedRunRkt(ctx, t, server.URL, "oauth-bogus-files", authFailedDownload)
}

func testAuthIgnoreSubdirectories(t *testing.T, server *taas.Server) {
ctx := newRktRunCtx()
defer ctx.cleanup()
localSubdir := filepath.Join(ctx.localDir(), "subdir")
systemSubdir := filepath.Join(ctx.systemDir(), "subdir")
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
localSubdir := filepath.Join(ctx.LocalDir(), "subdir")
systemSubdir := filepath.Join(ctx.SystemDir(), "subdir")
writeConfig(t, localSubdir, "test.json", server.Conf)
writeConfig(t, systemSubdir, "test.json", server.Conf)
expectedRunRkt(ctx, t, server.URL, "oauth-subdirectories", authFailedDownload)
}

func runServer(t *testing.T, auth taas.Type) *taas.Server {
actool := getValueFromEnvOrPanic("ACTOOL")
gotool := getValueFromEnvOrPanic("GO")
actool := testutils.GetValueFromEnvOrPanic("ACTOOL")
gotool := testutils.GetValueFromEnvOrPanic("GO")
server, err := taas.NewServerWithPaths(auth, 20, actool, gotool)
if err != nil {
t.Fatalf("Could not start server: %v", err)
Expand All @@ -170,10 +171,10 @@ func serverHandler(t *testing.T, server *taas.Server) {
// given directory on host. Note that directory can be anything - it's
// useful for ensuring that image name is unique and for descriptive
// purposes.
func expectedRunRkt(ctx *rktRunCtx, t *testing.T, host, dir, line string) {
func expectedRunRkt(ctx *testutils.RktRunCtx, t *testing.T, host, dir, line string) {
// First, check that --insecure-skip-verify is required
// The server does not provide signatures for now.
cmd := fmt.Sprintf(`%s --debug run --mds-register=false %s/%s/prog.aci`, ctx.cmd(), host, dir)
cmd := fmt.Sprintf(`%s --debug run --mds-register=false %s/%s/prog.aci`, ctx.Cmd(), host, dir)
child := spawnOrFail(t, cmd)
defer child.Wait()
signatureErrorLine := "error downloading the signature file"
Expand All @@ -182,7 +183,7 @@ func expectedRunRkt(ctx *rktRunCtx, t *testing.T, host, dir, line string) {
}

// Then, run with --insecure-skip-verify
cmd = fmt.Sprintf(`%s --debug --insecure-skip-verify run --mds-register=false %s/%s/prog.aci`, ctx.cmd(), host, dir)
cmd = fmt.Sprintf(`%s --debug --insecure-skip-verify run --mds-register=false %s/%s/prog.aci`, ctx.Cmd(), host, dir)
child = spawnOrFail(t, cmd)
defer child.Wait()
if err := expectWithOutput(child, line); err != nil {
Expand Down
17 changes: 9 additions & 8 deletions tests/rkt_caps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/coreos/rkt/Godeps/_workspace/src/github.com/syndtr/gocapability/capability"
"github.com/coreos/rkt/tests/testutils"
)

var capsTests = []struct {
Expand Down Expand Up @@ -73,8 +74,8 @@ var capsTests = []struct {
}

func TestCaps(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

for i, tt := range capsTests {
stage1Args := []string{"--exec=/inspect --print-caps-pid=1 --print-user"}
Expand All @@ -92,7 +93,7 @@ func TestCaps(t *testing.T) {
for _, stage := range []int{1, 2} {
t.Logf("Running test #%v: %v [stage %v]", i, tt.testName, stage)

cmd := fmt.Sprintf("%s --debug --insecure-skip-verify run --mds-register=false --set-env=CAPABILITY=%d %s", ctx.cmd(), int(tt.capa), stageFileNames[stage-1])
cmd := fmt.Sprintf("%s --debug --insecure-skip-verify run --mds-register=false --set-env=CAPABILITY=%d %s", ctx.Cmd(), int(tt.capa), stageFileNames[stage-1])
child := spawnOrFail(t, cmd)

expectedLine := tt.capa.String()
Expand All @@ -110,13 +111,13 @@ func TestCaps(t *testing.T) {
}
waitOrFail(t, child, true)
}
ctx.reset()
ctx.Reset()
}
}

func TestCapsNonRoot(t *testing.T) {
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

for i, tt := range capsTests {
args := []string{"--exec=/inspect --print-caps-pid=0 --print-user", "--user=9000", "--group=9000"}
Expand All @@ -128,7 +129,7 @@ func TestCapsNonRoot(t *testing.T) {

t.Logf("Running test #%v: %v [non-root]", i, tt.testName)

cmd := fmt.Sprintf("%s --debug --insecure-skip-verify run --mds-register=false --set-env=CAPABILITY=%d %s", ctx.cmd(), int(tt.capa), fileName)
cmd := fmt.Sprintf("%s --debug --insecure-skip-verify run --mds-register=false --set-env=CAPABILITY=%d %s", ctx.Cmd(), int(tt.capa), fileName)
child := spawnOrFail(t, cmd)

expectedLine := tt.capa.String()
Expand All @@ -146,6 +147,6 @@ func TestCapsNonRoot(t *testing.T) {
}

waitOrFail(t, child, true)
ctx.reset()
ctx.Reset()
}
}
8 changes: 5 additions & 3 deletions tests/rkt_cat_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"strings"
"testing"

"github.com/coreos/rkt/tests/testutils"
)

const (
Expand Down Expand Up @@ -48,8 +50,8 @@ func TestCatManifest(t *testing.T) {

testImage := patchTestACI("rkt-inspect-image-cat-manifest.aci", "--manifest", tmpManifest.Name())
defer os.Remove(testImage)
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

testImageHash := importImageAndFetchHash(t, ctx, testImage)

Expand Down Expand Up @@ -81,7 +83,7 @@ func TestCatManifest(t *testing.T) {
}

for i, tt := range tests {
runCmd := fmt.Sprintf("%s image cat-manifest %s", ctx.cmd(), tt.image)
runCmd := fmt.Sprintf("%s image cat-manifest %s", ctx.Cmd(), tt.image)
t.Logf("Running test #%d", i)
runRktAndCheckOutput(t, runCmd, tt.expect, !tt.shouldFind)
}
Expand Down
10 changes: 6 additions & 4 deletions tests/rkt_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"os"
"strings"
"testing"

"github.com/coreos/rkt/tests/testutils"
)

var envTests = []struct {
Expand Down Expand Up @@ -71,12 +73,12 @@ func TestEnv(t *testing.T) {
defer os.Remove(printVarOtherImage)
sleepImage := patchTestACI("rkt-inspect-sleep.aci", "--exec=/inspect --read-stdin")
defer os.Remove(sleepImage)
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

replacePlaceholders := func(cmd string) string {
fixed := cmd
fixed = strings.Replace(fixed, "^RKT_BIN^", ctx.cmd(), -1)
fixed = strings.Replace(fixed, "^RKT_BIN^", ctx.Cmd(), -1)
fixed = strings.Replace(fixed, "^PRINT_VAR_FROM_MANIFEST^", printVarFromManifestImage, -1)
fixed = strings.Replace(fixed, "^PRINT_VAR_OTHER^", printVarOtherImage, -1)
fixed = strings.Replace(fixed, "^SLEEP^", sleepImage, -1)
Expand Down Expand Up @@ -115,6 +117,6 @@ func TestEnv(t *testing.T) {
}

waitOrFail(t, child, true)
ctx.reset()
ctx.Reset()
}
}
7 changes: 4 additions & 3 deletions tests/rkt_etc_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/coreos/rkt/Godeps/_workspace/src/github.com/steveeJ/gexpect"
"github.com/coreos/rkt/tests/testutils"
)

// stage1/prepare-app will populate /etc/hosts with a 127.0.0.1 entry when absent,
Expand All @@ -46,8 +47,8 @@ func TestPrepareAppEnsureEtcHosts(t *testing.T) {
defer os.Remove(etcHostsCreateImage)
etcHostsExistsImage := patchTestACI("rkt-inspect-etc-hosts-exists.aci", "--exec=/inspect --read-file", "--mounts=etc,path=/etc,readOnly=false")
defer os.Remove(etcHostsExistsImage)
ctx := newRktRunCtx()
defer ctx.cleanup()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()

tmpdir := createTempDirOrPanic("rkt-tests.")
defer os.RemoveAll(tmpdir)
Expand All @@ -61,7 +62,7 @@ func TestPrepareAppEnsureEtcHosts(t *testing.T) {

for i, tt := range etcHostsTests {
cmd := strings.Replace(tt.rktCmd, "^TMPDIR^", tmpdir, -1)
cmd = strings.Replace(cmd, "^RKT_BIN^", ctx.cmd(), -1)
cmd = strings.Replace(cmd, "^RKT_BIN^", ctx.Cmd(), -1)
cmd = strings.Replace(cmd, "^ETC_HOSTS_CREATE^", etcHostsCreateImage, -1)
cmd = strings.Replace(cmd, "^ETC_HOSTS_EXISTS^", etcHostsExistsImage, -1)
cmd = strings.Replace(cmd, "^TMPETC^", tmpetc, -1)
Expand Down
Loading