github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/plugin/etcd_backup_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  	v1 "github.com/alibaba/sealer/types/api/v1"
    22  	v2 "github.com/alibaba/sealer/types/api/v2"
    23  )
    24  
    25  func TestEtcdBackupPlugin_Run(t *testing.T) {
    26  	type args struct {
    27  		context Context
    28  		phase   Phase
    29  	}
    30  
    31  	cluster := &v2.Cluster{}
    32  	cluster.Spec.SSH.User = "root"
    33  	cluster.Spec.SSH.Passwd = "123456"
    34  	cluster.Spec.Hosts = []v2.Host{
    35  		{
    36  			IPS:   []string{"192.168.0.2"},
    37  			Roles: []string{common.MASTER},
    38  		},
    39  	}
    40  	plugin := v1.Plugin{}
    41  	plugin.Spec.On = "/tmp/202108112058.bak"
    42  	tests := []struct {
    43  		name    string
    44  		args    args
    45  		wantErr bool
    46  	}{
    47  		{
    48  			"test label to cluster node",
    49  			args{
    50  				context: Context{
    51  					Cluster: cluster,
    52  					Plugin:  &plugin,
    53  				},
    54  				phase: PhasePostInstall,
    55  			},
    56  			false,
    57  		},
    58  	}
    59  	for _, tt := range tests {
    60  		t.Run(tt.name, func(t *testing.T) {
    61  			e := EtcdBackupPlugin{}
    62  			if err := e.Run(tt.args.context, tt.args.phase); (err != nil) != tt.wantErr {
    63  				t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
    64  			}
    65  		})
    66  	}
    67  }