github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/plugin/plugins_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  	v1 "github.com/alibaba/sealer/types/api/v1"
    21  	v2 "github.com/alibaba/sealer/types/api/v2"
    22  )
    23  
    24  func TestDumperPlugin_Run(t *testing.T) {
    25  	type fields struct {
    26  		configs     []v1.Plugin
    27  		clusterName string
    28  	}
    29  	type args struct {
    30  		cluster *v2.Cluster
    31  		phase   Phase
    32  	}
    33  	plugins := []v1.Plugin{
    34  		{
    35  			Spec: v1.PluginSpec{
    36  				On:     "node-role.kubernetes.io/master=",
    37  				Data:   "kubectl taint nodes node-role.kubernetes.io/master=:NoSchedule",
    38  				Action: "PostInstall",
    39  			},
    40  		},
    41  	}
    42  	//TODO cluster is where?
    43  	cluster := &v2.Cluster{}
    44  	tests := []struct {
    45  		name    string
    46  		fields  fields
    47  		args    args
    48  		wantErr bool
    49  	}{
    50  		{
    51  			name: "Test",
    52  			fields: fields{
    53  				configs:     plugins,
    54  				clusterName: "my-cluster",
    55  			},
    56  			args: args{
    57  				cluster: cluster,
    58  				phase:   "PostInstall",
    59  			},
    60  		},
    61  	}
    62  	for _, tt := range tests {
    63  		t.Run(tt.name, func(t *testing.T) {
    64  			c := &PluginsProcessor{
    65  				Plugins: tt.fields.configs,
    66  				Cluster: &v2.Cluster{},
    67  			}
    68  			c.Cluster.Name = tt.fields.clusterName
    69  			if err := c.Run(tt.args.cluster.GetAllIPList(), tt.args.phase); (err != nil) != tt.wantErr {
    70  				t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
    71  			}
    72  		})
    73  	}
    74  }