github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/container_create_windows_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  	"time"
    22  
    23  	"github.com/containerd/nerdctl/pkg/testutil"
    24  )
    25  
    26  func TestCreateProcessContainer(t *testing.T) {
    27  	base := testutil.NewBase(t)
    28  	tID := testutil.Identifier(t)
    29  
    30  	base.Cmd("create", "--name", tID, testutil.CommonImage, "echo", "foo").AssertOK()
    31  	defer base.Cmd("rm", "-f", tID).Run()
    32  	base.Cmd("ps", "-a").AssertOutContains("Created")
    33  	base.Cmd("start", tID).AssertOK()
    34  	base.Cmd("logs", tID).AssertOutContains("foo")
    35  }
    36  
    37  func TestCreateHyperVContainer(t *testing.T) {
    38  	base := testutil.NewBase(t)
    39  	tID := testutil.Identifier(t)
    40  
    41  	if !testutil.HyperVSupported() {
    42  		t.Skip("HyperV is not enabled, skipping test")
    43  	}
    44  
    45  	base.Cmd("create", "--isolation", "hyperv", "--name", tID, testutil.CommonImage, "echo", "foo").AssertOK()
    46  	defer base.Cmd("rm", "-f", tID).Run()
    47  	base.Cmd("ps", "-a").AssertOutContains("Created")
    48  
    49  	base.Cmd("start", tID).AssertOK()
    50  	// hyperv containers take a few seconds to fire up, the test would fail without the sleep
    51  	// EnsureContainerStarted does not work
    52  	time.Sleep(10 * time.Second)
    53  
    54  	base.Cmd("logs", tID).AssertOutContains("foo")
    55  }