github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/plugin/hostname_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  	v1 "github.com/alibaba/sealer/types/api/v1"
    21  )
    22  
    23  /*
    24  apiVersion: sealer.aliyun.com/v1alpha1
    25  kind: Plugin
    26  metadata:
    27    name: HOSTNAME
    28  spec:
    29    type: LABEL
    30    data: |
    31       192.168.0.2 master-0
    32       192.168.0.3 master-1
    33       192.168.0.4 master-2
    34       192.168.0.5 node-0
    35       192.168.0.6 node-1
    36       192.168.0.7 node-2
    37  */
    38  func TestHostnamePlugin_Run(t *testing.T) {
    39  	type fields struct {
    40  		data map[string]string
    41  	}
    42  
    43  	type args struct {
    44  		context Context
    45  		phase   Phase
    46  	}
    47  
    48  	plugin := &v1.Plugin{}
    49  	plugin.Spec.Data = "192.168.0.2 master-0\n192.168.0.3 master-1\n192.168.0.4 master-2\n192.168.0.5 node-0\n192.168.0.6 node-1\n192.168.0.7 node-2\n"
    50  
    51  	tests := []struct {
    52  		name    string
    53  		fields  fields
    54  		args    args
    55  		wantErr bool
    56  	}{
    57  		// TODO: Add test cases.
    58  		{
    59  			"test hostnameChange to cluster node",
    60  			fields{},
    61  			args{
    62  				context: Context{
    63  					Plugin: plugin,
    64  				},
    65  				phase: PhasePreInit,
    66  			},
    67  			false,
    68  		},
    69  	}
    70  	for _, tt := range tests {
    71  		t.Run(tt.name, func(t *testing.T) {
    72  			h := HostnamePlugin{
    73  				data: tt.fields.data,
    74  			}
    75  			if err := h.Run(tt.args.context, tt.args.phase); (err != nil) != tt.wantErr {
    76  				t.Errorf("HostnamePlugins.Run() error = %v, wantErr %v", err, tt.wantErr)
    77  			}
    78  		})
    79  	}
    80  }