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

Commit

Permalink
functional tests: add tests for rkt rm
Browse files Browse the repository at this point in the history
  • Loading branch information
iaguis committed May 24, 2016
1 parent a111a6b commit e7cf59f
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tests/rkt_rm_test.go
@@ -0,0 +1,101 @@
// 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 host coreos src kvm

package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

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

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

var uuids []string

img := patchTestACI("inspect-rm-test-run.aci", []string{"--exec=/inspect --print-msg=HELLO_API --exit-code=0"}...)
defer os.Remove(img)
prepareCmd := fmt.Sprintf("%s --insecure-options=image prepare %s", ctx.Cmd(), img)

// Finished pod.
uuid := runRktAndGetUUID(t, prepareCmd)
runPreparedCmd := fmt.Sprintf("%s --insecure-options=image run-prepared %s", ctx.Cmd(), uuid)
runRktAndCheckOutput(t, runPreparedCmd, "", false)

uuids = append(uuids, uuid)

// Prepared pod.
uuid = runRktAndGetUUID(t, prepareCmd)
uuids = append(uuids, uuid)

podDirs := []string{
filepath.Join(ctx.DataDir(), "pods", "run"),
filepath.Join(ctx.DataDir(), "pods", "prepared"),
}

for _, dir := range podDirs {
pods, err := ioutil.ReadDir(dir)
if err != nil {
t.Fatalf("cannot read pods directory %q: %v", dir, err)
}
if len(pods) == 0 {
t.Fatalf("pods should still exist in directory %q: %v", dir, pods)
}
}

for _, u := range uuids {
cmd := fmt.Sprintf("%s rm %s", ctx.Cmd(), u)
spawnAndWaitOrFail(t, cmd, 0)
}

podDirs = append(podDirs, filepath.Join(ctx.DataDir(), "pods", "exited-garbage"))

for _, dir := range podDirs {
pods, err := ioutil.ReadDir(dir)
if err != nil {
t.Fatalf("cannot read pods directory %q: %v", dir, err)
}
if len(pods) != 0 {
t.Fatalf("no pods should exist in directory %q, but found: %v", dir, pods)
}
}
}

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

nonexistentUUID := "0f746094-3438-42bc-ab37-3cf85f132e60"
tmpDir := createTempDirOrPanic("rkt_rm_test")
uuidFile := filepath.Join(tmpDir, "uuid-file")
if err := ioutil.WriteFile(uuidFile, []byte(nonexistentUUID), 0600); err != nil {
t.Fatalf("cannot write uuid-file: %v", err)
}

expected := fmt.Sprintf("no matches found for %q", nonexistentUUID)

cmd := fmt.Sprintf("%s rm %s", ctx.Cmd(), nonexistentUUID)
runRktAndCheckOutput(t, cmd, expected, true)

cmd = fmt.Sprintf("%s rm --uuid-file=%s", ctx.Cmd(), uuidFile)
runRktAndCheckOutput(t, cmd, expected, true)
}

0 comments on commit e7cf59f

Please sign in to comment.