github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/build/layerutils/utils_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 layerutils
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func Test_decodeImages(t *testing.T) {
    23  	body := `
    24            image: cn-app-integration:v1.0.0
    25            image: registry.cn-shanghai.aliyuncs.com/cnip/cn-app-integration:v1.0.0
    26            imagePullPolicy: Always
    27            image: cn-app-integration:v1.0.0
    28  		  # image: cn-app-integration:v1.0.0
    29            name: cn-app-demo`
    30  	type args struct {
    31  		body string
    32  	}
    33  	tests := []struct {
    34  		name string
    35  		args args
    36  		want []string
    37  	}{
    38  		{
    39  			"test get iamges form yaml",
    40  			args{body},
    41  			[]string{"cn-app-integration:v1.0.0", "registry.cn-shanghai.aliyuncs.com/cnip/cn-app-integration:v1.0.0", "cn-app-integration:v1.0.0"},
    42  		},
    43  	}
    44  	for _, tt := range tests {
    45  		t.Run(tt.name, func(t *testing.T) {
    46  			if got := DecodeImages(tt.args.body); !reflect.DeepEqual(got, tt.want) {
    47  				t.Errorf("decodeImages() = %v, want %v", got, tt.want)
    48  			}
    49  		})
    50  	}
    51  }