...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf/conversion_test.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf

     1  // Copyright 2022 Google LLC
     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 krmtotf_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf"
    21  )
    22  
    23  func TestKRMNameToTerraformID(t *testing.T) {
    24  	tests := []struct {
    25  		name    string
    26  		krmName string
    27  		want    string
    28  	}{
    29  		{
    30  			name:    "only alphanumerics",
    31  			krmName: "badabingbadazoom128",
    32  			want:    "badabingbadazoom128",
    33  		},
    34  		{
    35  			name:    "dashes should become underscores",
    36  			krmName: "x-y-z",
    37  			want:    "x_y_z",
    38  		},
    39  		{
    40  			name:    "dots should become underscores",
    41  			krmName: "x.y.z",
    42  			want:    "x_y_z",
    43  		},
    44  		{
    45  			name:    "dashes and dots in same string",
    46  			krmName: "x.y-z",
    47  			want:    "x_y_z",
    48  		},
    49  	}
    50  	for _, tc := range tests {
    51  		tc := tc
    52  		t.Run(tc.name, func(t *testing.T) {
    53  			t.Parallel()
    54  			got := krmtotf.KRMNameToTerraformID(tc.krmName)
    55  			if got != tc.want {
    56  				t.Errorf("KRMNameToTerraformId(%v) = %v, want: %v", tc.krmName, got, tc.want)
    57  			}
    58  		})
    59  	}
    60  }
    61  

View as plain text