github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/env/env_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 env 16 17 import ( 18 "testing" 19 ) 20 21 func Test_processor_WrapperShell(t *testing.T) { 22 type args struct { 23 wrapperData map[string]string 24 shell string 25 } 26 tests := []struct { 27 name string 28 args args 29 want string 30 }{ 31 { 32 "test WrapperShell ", 33 args{ 34 wrapperData: map[string]string{ 35 "foo": "bar", 36 "IP": "127.0.0.1", 37 }, 38 shell: "hostname", 39 }, 40 "export IP=\"127.0.0.1\"; export foo=\"bar\"; hostname", 41 }, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 if got := WrapperShell(tt.args.shell, tt.args.wrapperData); got != tt.want { 46 t.Errorf("WrapperShell() = %v, want %v", got, tt.want) 47 } 48 }) 49 } 50 } 51 52 func Test_processor_RenderAll(t *testing.T) { 53 type args struct { 54 renderData map[string]string 55 dir string 56 } 57 tests := []struct { 58 name string 59 args args 60 wantErr bool 61 }{ 62 { 63 "test render dir", 64 args{ 65 renderData: map[string]string{ 66 "PodCIDR": "100.64.0.0/10", 67 "SvcCIDR": "10.96.0.0/16", 68 }, 69 dir: "test/template", 70 }, 71 false, 72 }, 73 } 74 75 for _, tt := range tests { 76 t.Run(tt.name, func(t *testing.T) { 77 if err := RenderTemplate(tt.args.dir, tt.args.renderData); (err != nil) != tt.wantErr { 78 t.Errorf("RenderAll() error = %v, wantErr %v", err, tt.wantErr) 79 } 80 }) 81 } 82 }