github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/clustercert/kube_certs_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 clustercert 16 17 import ( 18 "net" 19 "testing" 20 ) 21 22 func TestGenerateAll(t *testing.T) { 23 basePath := "/tmp/kubernetes/pki" 24 etcdBasePath := "/tmp/kubernetes/pki/etcd" 25 tests := []struct { 26 name string 27 wantErr bool 28 }{ 29 { 30 "generate all certs", 31 false, 32 }, 33 } 34 35 for _, tt := range tests { 36 t.Run(tt.name, func(t *testing.T) { 37 if err := GenerateAllKubernetesCerts(basePath, etcdBasePath, "master1", "10.64.0.0/10", "cluster.local", []string{"test.com", "192.168.1.2", "kubernetes.default.svc.sealyun"}, net.ParseIP("172.27.139.11")); (err != nil) != tt.wantErr { 38 t.Errorf("GenerateAll() error = %v, wantErr %v", err, tt.wantErr) 39 } 40 }) 41 } 42 } 43 44 func TestUpdateAPIServerCert(t *testing.T) { 45 tests := []struct { 46 pkiPath string 47 certSans []string 48 name string 49 wantErr bool 50 }{ 51 {"/tmp/kubernetes/pki", 52 []string{"kaka.com", "apiserver.cluster.local", "192.168.1.100"}, 53 "Update APIServer Cert sans", 54 false, 55 }, 56 } 57 58 for _, tt := range tests { 59 t.Run(tt.name, func(t *testing.T) { 60 if err := UpdateAPIServerCertSans(tt.pkiPath, tt.certSans); (err != nil) != tt.wantErr { 61 t.Errorf("UpdateAPIServerCert() error = %v, wantErr %v", err, tt.wantErr) 62 } 63 }) 64 } 65 }