github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/completion_linux_test.go (about)

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/containerd/nerdctl/pkg/testutil"
    23  )
    24  
    25  func TestCompletion(t *testing.T) {
    26  	testutil.DockerIncompatible(t)
    27  	base := testutil.NewBase(t)
    28  	const gsc = "__complete"
    29  	// cmd is executed with base.Args={"--namespace=nerdctl-test"}
    30  	base.Cmd(gsc, "--cgroup-manager", "").AssertOutContains("cgroupfs\n")
    31  	base.Cmd(gsc, "--snapshotter", "").AssertOutContains("native\n")
    32  	base.Cmd(gsc, "").AssertOutContains("run\t")
    33  	base.Cmd(gsc, "run", "-").AssertOutContains("--network\t")
    34  	base.Cmd(gsc, "run", "--n").AssertOutContains("--network\t")
    35  	base.Cmd(gsc, "run", "--ne").AssertOutContains("--network\t")
    36  	base.Cmd(gsc, "run", "--net", "").AssertOutContains("host\n")
    37  	base.Cmd(gsc, "run", "-it", "--net", "").AssertOutContains("host\n")
    38  	base.Cmd(gsc, "run", "-it", "--rm", "--net", "").AssertOutContains("host\n")
    39  	base.Cmd(gsc, "run", "--restart", "").AssertOutContains("always\n")
    40  	base.Cmd(gsc, "network", "rm", "").AssertNoOut("host\n") // host is unremovable
    41  	base.Cmd(gsc, "run", "--cap-add", "").AssertOutContains("sys_admin\n")
    42  	base.Cmd(gsc, "run", "--cap-add", "").AssertNoOut("CAP_SYS_ADMIN\n") // invalid form
    43  
    44  	// Tests with an image
    45  	base.Cmd("pull", testutil.AlpineImage).AssertOK()
    46  	base.Cmd(gsc, "run", "-i", "").AssertOutContains(testutil.AlpineImage)
    47  	base.Cmd(gsc, "run", "-it", "").AssertOutContains(testutil.AlpineImage)
    48  	base.Cmd(gsc, "run", "-it", "--rm", "").AssertOutContains(testutil.AlpineImage)
    49  
    50  	// Tests with a network
    51  	testNetworkName := "nerdctl-test-completion"
    52  	defer base.Cmd("network", "rm", testNetworkName).Run()
    53  	base.Cmd("network", "create", testNetworkName).AssertOK()
    54  	base.Cmd(gsc, "network", "rm", "").AssertOutContains(testNetworkName)
    55  	base.Cmd(gsc, "run", "--net", "").AssertOutContains(testNetworkName)
    56  
    57  	// Tests with a volume
    58  	testVolumekName := "nerdctl-test-completion"
    59  	defer base.Cmd("volume", "rm", testVolumekName).Run()
    60  	base.Cmd("volume", "create", testVolumekName).AssertOK()
    61  	base.Cmd(gsc, "volume", "inspect", "").AssertOutContains(testVolumekName)
    62  	base.Cmd(gsc, "volume", "rm", "").AssertOutContains(testVolumekName)
    63  
    64  	// Tests with raw base (without Args={"--namespace=nerdctl-test"})
    65  	rawBase := testutil.NewBase(t)
    66  	rawBase.Args = nil // unset "--namespace=nerdctl-test"
    67  	rawBase.Cmd(gsc, "--cgroup-manager", "").AssertOutContains("cgroupfs\n")
    68  	rawBase.Cmd(gsc, "").AssertOutContains("run\t")
    69  	// mind {"--namespace=nerdctl-test"} vs {"--namespace", "nerdctl-test"}
    70  	rawBase.Cmd(gsc, "--namespace", testutil.Namespace, "").AssertOutContains("run\t")
    71  	rawBase.Cmd(gsc, "--namespace", testutil.Namespace, "run", "-i", "").AssertOutContains(testutil.AlpineImage)
    72  }