github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/ipvs/ipvs_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 ipvs
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  var want = []string{
    22  	`apiVersion: v1
    23  kind: Pod
    24  metadata:
    25    creationTimestamp: null
    26    labels:
    27      component: kube-sealyun-lvscare
    28      tier: control-plane
    29    name: kube-sealyun-lvscare
    30    namespace: kube-system
    31  spec:
    32    containers:
    33    - args:
    34      - care
    35      - --vs
    36      - 10.10.10.10:6443
    37      - --health-path
    38      - /healthz
    39      - --health-schem
    40      - https
    41      - --rs
    42      - 116.31.96.134:6443
    43      - --rs
    44      - 116.31.96.135:6443
    45      - --rs
    46      - 116.31.96.136:6443
    47      command:
    48      - /usr/bin/lvscare
    49      image: fanux/lvscare:latest
    50      imagePullPolicy: IfNotPresent
    51      name: kube-sealyun-lvscare
    52      resources: {}
    53      securityContext:
    54        privileged: true
    55      volumeMounts:
    56      - mountPath: /lib/modules
    57        name: lib-modules
    58        readOnly: true
    59    hostNetwork: true
    60    priorityClassName: system-cluster-critical
    61    volumes:
    62    - hostPath:
    63        path: /lib/modules
    64        type: ""
    65      name: lib-modules
    66  status: {}
    67  `,
    68  }
    69  
    70  func TestLvsStaticPodYaml(t *testing.T) {
    71  	type args struct {
    72  		vip     string
    73  		masters []string
    74  		image   string
    75  	}
    76  	tests := []struct {
    77  		name string
    78  		args args
    79  		want string
    80  	}{
    81  		{
    82  			"test generate lvs care static pod",
    83  			args{
    84  				"10.10.10.10",
    85  				[]string{"116.31.96.134:6443", "116.31.96.135:6443", "116.31.96.136:6443"},
    86  				"fanux/lvscare:latest",
    87  			},
    88  			want[0],
    89  		},
    90  	}
    91  	for _, tt := range tests {
    92  		t.Run(tt.name, func(t *testing.T) {
    93  			if got := LvsStaticPodYaml(tt.args.vip, tt.args.masters, tt.args.image); got != tt.want {
    94  				t.Errorf("LvsStaticPodYaml() = %v, want %v", got, tt.want)
    95  			}
    96  		})
    97  	}
    98  }