github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/plugin/shell_plugin_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 plugin 16 17 import ( 18 "testing" 19 20 "github.com/alibaba/sealer/common" 21 typev1 "github.com/alibaba/sealer/types/api/v1" 22 typev2 "github.com/alibaba/sealer/types/api/v2" 23 ) 24 25 /* 26 27 apiVersion: sealer.aliyun.com/v1alpha1 28 kind: Plugin 29 metadata: 30 name: SHELL 31 spec: 32 type: SHELL 33 action: PostInstall 34 on: role=master 35 data: | 36 kubectl taint nodes node-role.kubernetes.io/master=:NoSchedule 37 38 */ 39 func TestSheller_Run(t *testing.T) { 40 type args struct { 41 context Context 42 phase Phase 43 } 44 45 cluster := &typev2.Cluster{} 46 cluster.Spec.SSH.User = "root" 47 cluster.Spec.SSH.Passwd = "7758521" 48 cluster.Spec.Hosts = []typev2.Host{ 49 { 50 IPS: []string{"192.168.59.11"}, 51 Roles: []string{common.MASTER}, 52 }, 53 } 54 //cluster.Spec.Nodes.IPList = []string{"192.168.59.11"} 55 plugin := &typev1.Plugin{} 56 plugin.Spec.Data = "ifconfig" 57 58 tests := []struct { 59 name string 60 args args 61 wantErr bool 62 }{ 63 // TODO: Add test cases. 64 { 65 name: "test shell plugin", 66 args: args{ 67 context: Context{ 68 Cluster: cluster, 69 Plugin: plugin, 70 }, 71 phase: Phase(plugin.Spec.On), 72 }, 73 wantErr: false, 74 }, 75 } 76 77 for _, tt := range tests { 78 t.Run(tt.name, func(t *testing.T) { 79 s := Sheller{} 80 if err := s.Run(tt.args.context, tt.args.phase); (err != nil) != tt.wantErr { 81 t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr) 82 } 83 }) 84 } 85 }