k8c.io/api/v3@v3.0.0-20230904060738-b0a93889c0b6/pkg/apis/kubermatic/v1/helper/machine_controller_test.go (about) 1 /* 2 Copyright 2023 The Kubermatic Kubernetes Platform contributors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package helper 18 19 import ( 20 "testing" 21 22 kubermaticv1 "k8c.io/api/v3/pkg/apis/kubermatic/v1" 23 24 "k8s.io/apimachinery/pkg/util/sets" 25 ) 26 27 func TestMapCloudProvider(t *testing.T) { 28 for _, kkpProvider := range sets.List(kubermaticv1.AllCloudProviders) { 29 t.Run(string(kkpProvider), func(t *testing.T) { 30 // provider has purposefully no mapping 31 if kkpProvider == kubermaticv1.CloudProviderBringYourOwn { 32 return 33 } 34 35 mcProvider, err := CloudProviderToMachineController(kkpProvider) 36 if err != nil { 37 t.Fatalf("Cannot map cloud provider %q to machine-controller: %v", kkpProvider, err) 38 } 39 40 mapped, err := CloudProviderToKKP(mcProvider) 41 if err != nil { 42 t.Fatalf("Cannot map cloud provider %q (originally %q) back to KKP: %v", mcProvider, kkpProvider, err) 43 } 44 45 if mapped != kkpProvider { 46 t.Fatalf("%q in KKP maps to %q in machine-controller, but in reverse maps to %q", kkpProvider, mcProvider, mapped) 47 } 48 }) 49 } 50 } 51 52 func TestMapOperatingSystem(t *testing.T) { 53 for _, kkpOperatingSystem := range sets.List(kubermaticv1.AllOperatingSystems) { 54 t.Run(string(kkpOperatingSystem), func(t *testing.T) { 55 mcOperatingSystem, err := OperatingSystemToMachineController(kkpOperatingSystem) 56 if err != nil { 57 t.Fatalf("Cannot map operating system %q to machine-controller: %v", kkpOperatingSystem, err) 58 } 59 60 mapped, err := OperatingSystemToKKP(mcOperatingSystem) 61 if err != nil { 62 t.Fatalf("Cannot map operating system %q (originally %q) back to KKP: %v", mcOperatingSystem, kkpOperatingSystem, err) 63 } 64 65 if mapped != kkpOperatingSystem { 66 t.Fatalf("%q in KKP maps to %q in machine-controller, but in reverse maps to %q", kkpOperatingSystem, mcOperatingSystem, mapped) 67 } 68 }) 69 } 70 }