github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/config/pre_process_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 config 16 17 import ( 18 "encoding/base64" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 23 v1 "github.com/sealerio/sealer/types/api/v1" 24 ) 25 26 func TestNewProcessorsAndRun(t *testing.T) { 27 tests := []struct { 28 name string 29 config *v1.Config 30 wantData string 31 wantErr bool 32 }{ 33 { 34 name: "value|toJson|toBase64|toSecret", 35 config: &v1.Config{ 36 Spec: v1.ConfigSpec{ 37 Process: "value|toJson|toBase64|toSecret", 38 Data: ` 39 config: 40 username: root 41 passwd: xxx 42 `, 43 }, 44 }, 45 wantData: "config: " + base64.StdEncoding.EncodeToString([]byte(`{"passwd":"xxx","username":"root"}`)) + "\n", 46 wantErr: false, 47 }, 48 } 49 50 for _, tt := range tests { 51 t.Run(tt.name, func(t *testing.T) { 52 if err := NewProcessorsAndRun(tt.config); (err != nil) != tt.wantErr { 53 t.Errorf("NewProcessorsAndRun() error = %v, wantErr %v", err, tt.wantErr) 54 } 55 56 assert.Equal(t, tt.wantData, tt.config.Spec.Data) 57 }) 58 } 59 }