github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/tests/rkt_list_test.go (about)

     1  // Copyright 2015 The rkt Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"fmt"
    19  	"os"
    20  	"testing"
    21  
    22  	"github.com/coreos/rkt/tests/testutils"
    23  )
    24  
    25  func TestRktList(t *testing.T) {
    26  	const imgName = "rkt-list-test"
    27  
    28  	image := patchTestACI(fmt.Sprintf("%s.aci", imgName), fmt.Sprintf("--name=%s", imgName))
    29  	defer os.Remove(image)
    30  
    31  	imageHash := getHashOrPanic(image)
    32  	imgID := ImageId{image, imageHash}
    33  
    34  	ctx := testutils.NewRktRunCtx()
    35  	defer ctx.Cleanup()
    36  
    37  	// Prepare image
    38  	cmd := fmt.Sprintf("%s --insecure-skip-verify prepare %s", ctx.Cmd(), imgID.path)
    39  	podUuid := runRktAndGetUUID(t, cmd)
    40  
    41  	// Get hash
    42  	imageID := fmt.Sprintf("sha512-%s", imgID.hash[:12])
    43  
    44  	tmpDir := createTempDirOrPanic(imgName)
    45  	defer os.RemoveAll(tmpDir)
    46  
    47  	// Define tests
    48  	tests := []struct {
    49  		cmd           string
    50  		shouldSucceed bool
    51  		expect        string
    52  	}{
    53  		// Test that pod UUID is in output
    54  		{
    55  			"list --full",
    56  			true,
    57  			podUuid,
    58  		},
    59  		// Test that image name is in output
    60  		{
    61  			"list",
    62  			true,
    63  			imgName,
    64  		},
    65  		// Test that imageID is in output
    66  		{
    67  			"list --full",
    68  			true,
    69  			imageID,
    70  		},
    71  		// Remove the image
    72  		{
    73  			fmt.Sprintf("image rm %s", imageID),
    74  			true,
    75  			"successfully removed",
    76  		},
    77  		// Name should still show up in rkt list
    78  		{
    79  			"list",
    80  			true,
    81  			imgName,
    82  		},
    83  		// Test that imageID is still in output
    84  		{
    85  			"list --full",
    86  			true,
    87  			imageID,
    88  		},
    89  	}
    90  
    91  	// Run tests
    92  	for i, tt := range tests {
    93  		runCmd := fmt.Sprintf("%s %s", ctx.Cmd(), tt.cmd)
    94  		t.Logf("Running test #%d, %s", i, runCmd)
    95  		runRktAndCheckOutput(t, runCmd, tt.expect, !tt.shouldSucceed)
    96  	}
    97  }