github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/system_info_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  	"encoding/json"
    21  	"fmt"
    22  	"os"
    23  	"testing"
    24  
    25  	"github.com/containerd/nerdctl/pkg/infoutil"
    26  	"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
    27  	"github.com/containerd/nerdctl/pkg/testutil"
    28  )
    29  
    30  func testInfoJSON(stdout string) error {
    31  	var info dockercompat.Info
    32  	if err := json.Unmarshal([]byte(stdout), &info); err != nil {
    33  		return err
    34  	}
    35  	unameM := infoutil.UnameM()
    36  	if info.Architecture != unameM {
    37  		return fmt.Errorf("expected info.Architecture to be %q, got %q", unameM, info.Architecture)
    38  	}
    39  	return nil
    40  }
    41  
    42  func TestInfo(t *testing.T) {
    43  	base := testutil.NewBase(t)
    44  	base.Cmd("info", "--format", "{{json .}}").AssertOutWithFunc(testInfoJSON)
    45  }
    46  
    47  func TestInfoConvenienceForm(t *testing.T) {
    48  	testutil.DockerIncompatible(t) // until https://github.com/docker/cli/pull/3355 gets merged
    49  	base := testutil.NewBase(t)
    50  	base.Cmd("info", "--format", "json").AssertOutWithFunc(testInfoJSON)
    51  }
    52  
    53  func TestInfoWithNamespace(t *testing.T) {
    54  	testutil.DockerIncompatible(t)
    55  	base := testutil.NewBase(t)
    56  	base.Args = nil // unset "--namespace=nerdctl-test"
    57  
    58  	base.Cmd("info").AssertOutContains("Namespace:	default")
    59  
    60  	base.Env = append(os.Environ(), "CONTAINERD_NAMESPACE=test")
    61  	base.Cmd("info").AssertOutContains("Namespace:	test")
    62  }