github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/build/layerutils/manifests/manifests_test.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     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 manifest
    16  
    17  import (
    18  	"reflect"
    19  	"sort"
    20  	"testing"
    21  )
    22  
    23  func TestListImages(t *testing.T) {
    24  	type args struct {
    25  		clusterName string
    26  	}
    27  	tests := []struct {
    28  		name    string
    29  		args    args
    30  		want    []string
    31  		wantErr bool
    32  	}{
    33  		{
    34  			"test list manifests images",
    35  			args{"my_cluster"},
    36  			[]string{"k8s.gcr.io/etcd:3.4.13-0", "k8s.gcr.io/kube-apiserver:v1.19.7", "k8s.gcr.io/kube-controller-manager:v1.19.7", "k8s.gcr.io/kube-scheduler:v1.19.7"},
    37  			false,
    38  		},
    39  	}
    40  	manifests, _ := NewManifests()
    41  	for _, tt := range tests {
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			got, err := manifests.ListImages(tt.args.clusterName)
    44  			if (err != nil) != tt.wantErr {
    45  				t.Errorf("ListImages() error = %v, wantErr %v", err, tt.wantErr)
    46  				return
    47  			}
    48  			sort.Strings(got)
    49  			sort.Strings(tt.want)
    50  			if !reflect.DeepEqual(got, tt.want) {
    51  				t.Errorf("ListImages() got = %v, want %v", got, tt.want)
    52  			}
    53  		})
    54  	}
    55  }