github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/container_run_soci_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  	"os/exec"
    21  	"strings"
    22  	"testing"
    23  
    24  	"github.com/containerd/nerdctl/pkg/testutil"
    25  )
    26  
    27  func TestRunSoci(t *testing.T) {
    28  	testutil.DockerIncompatible(t)
    29  	tests := []struct {
    30  		name                         string
    31  		image                        string
    32  		remoteSnapshotsExpectedCount int
    33  	}{
    34  		{
    35  			name:                         "Run with SOCI",
    36  			image:                        testutil.FfmpegSociImage,
    37  			remoteSnapshotsExpectedCount: 11,
    38  		},
    39  	}
    40  
    41  	for _, tt := range tests {
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			base := testutil.NewBase(t)
    44  			requiresSoci(base)
    45  
    46  			//counting initial snapshot mounts
    47  			initialMounts, err := exec.Command("mount").Output()
    48  			if err != nil {
    49  				t.Fatal(err)
    50  			}
    51  
    52  			remoteSnapshotsInitialCount := strings.Count(string(initialMounts), "fuse.rawBridge")
    53  
    54  			runOutput := base.Cmd("--snapshotter=soci", "run", "--rm", testutil.FfmpegSociImage).Out()
    55  			base.T.Logf("run output: %s", runOutput)
    56  
    57  			actualMounts, err := exec.Command("mount").Output()
    58  			if err != nil {
    59  				t.Fatal(err)
    60  			}
    61  			remoteSnapshotsActualCount := strings.Count(string(actualMounts), "fuse.rawBridge")
    62  			base.T.Logf("number of actual mounts: %v", remoteSnapshotsActualCount)
    63  
    64  			rmiOutput := base.Cmd("rmi", testutil.FfmpegSociImage).Out()
    65  			base.T.Logf("rmi output: %s", rmiOutput)
    66  
    67  			base.T.Logf("number of expected mounts: %v", tt.remoteSnapshotsExpectedCount)
    68  
    69  			if tt.remoteSnapshotsExpectedCount != (remoteSnapshotsActualCount - remoteSnapshotsInitialCount) {
    70  				t.Fatalf("incorrect number of remote snapshots; expected=%d, actual=%d",
    71  					tt.remoteSnapshotsExpectedCount, remoteSnapshotsActualCount-remoteSnapshotsInitialCount)
    72  			}
    73  		})
    74  	}
    75  }
    76  
    77  func requiresSoci(base *testutil.Base) {
    78  	info := base.Info()
    79  	for _, p := range info.Plugins.Storage {
    80  		if p == "soci" {
    81  			return
    82  		}
    83  	}
    84  	base.T.Skip("test requires soci")
    85  }