Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
tests: add smoke test for app sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Nov 15, 2016
1 parent f6e7b86 commit f3f8a2a
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions tests/rkt_app_sandbox_test.go
@@ -0,0 +1,115 @@
// Copyright 2016 The rkt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !fly

package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"

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

// TestAppSandboxSmoke is a basic smoke test for `rkt app` sandbox
// and related commands.
func TestAppSandboxSmoke(t *testing.T) {
actionTimeout := 30 * time.Second
imageName := "coreos.com/rkt-inspect/hello"
appName := "hello-app"
msg := "HelloFromAppInSandbox"

aciHello := patchTestACI("rkt-inspect-hello.aci", fmt.Sprintf("--name=%s", imageName), fmt.Sprintf("--exec=/inspect --print-msg=%s", msg))
defer os.Remove(aciHello)

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

cmd := strings.Fields(fmt.Sprintf("%s fetch --insecure-options=image %s", ctx.Cmd(), aciHello))
fetchCmd := exec.Command(cmd[0], cmd[1:]...)
fetchCmd.Env = append(fetchCmd.Env, "RKT_EXPERIMENT_APP=true")
fetchOutput, err := fetchCmd.CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v\n%s", err, fetchOutput)
}

tmpDir := createTempDirOrPanic("rkt-test-cri-")
defer os.RemoveAll(tmpDir)

rktCmd := fmt.Sprintf("%s app sandbox --debug --uuid-file-save=%s/uuid", ctx.Cmd(), tmpDir)
err = os.Setenv("RKT_EXPERIMENT_APP", "true")
if err != nil {
panic(err)
}
child := spawnOrFail(t, rktCmd)
err = os.Unsetenv("RKT_EXPERIMENT_APP")
if err != nil {
panic(err)
}

expected := "Reached target rkt apps target."
if err := expectTimeoutWithOutput(child, expected, actionTimeout); err != nil {
t.Fatalf("Expected %q but not found: %v", expected, err)
}

podUUID, err := ioutil.ReadFile(filepath.Join(tmpDir, "uuid"))
if err != nil {
t.Fatalf("Can't read pod UUID: %v", err)
}

cmd = strings.Fields(fmt.Sprintf("%s app add --debug %s %s --name=%s", ctx.Cmd(), podUUID, imageName, appName))
addCmd := exec.Command(cmd[0], cmd[1:]...)
addCmd.Env = append(addCmd.Env, "RKT_EXPERIMENT_APP=true")
output, err := addCmd.CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v\n%s", err, output)
}

cmd = strings.Fields(fmt.Sprintf("%s app start --debug %s --app=%s", ctx.Cmd(), podUUID, appName))
startCmd := exec.Command(cmd[0], cmd[1:]...)
startCmd.Env = append(startCmd.Env, "RKT_EXPERIMENT_APP=true")
output, err = startCmd.CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v\n%s", err, output)
}

if err := expectTimeoutWithOutput(child, msg, actionTimeout); err != nil {
t.Fatalf("Expected %q but not found: %v", expected, err)
}

cmd = strings.Fields(fmt.Sprintf("%s app rm --debug %s --app=%s", ctx.Cmd(), podUUID, appName))
removeCmd := exec.Command(cmd[0], cmd[1:]...)
removeCmd.Env = append(removeCmd.Env, "RKT_EXPERIMENT_APP=true")
output, err = removeCmd.CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v\n%s", err, output)
}

cmd = strings.Fields(fmt.Sprintf("%s stop %s", ctx.Cmd(), podUUID))
output, err = exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
if err != nil {
t.Fatalf("Unexpected error: %v\n%s", err, output)
}

if err := child.Wait(); err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}

0 comments on commit f3f8a2a

Please sign in to comment.