github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/go/utilities_test.go (about)

     1  package gen
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMakeSafeEnumName(t *testing.T) {
     8  	t.Parallel()
     9  
    10  	tests := []struct {
    11  		input    string
    12  		expected string
    13  		wantErr  bool
    14  	}{
    15  		{"+", "", true},
    16  		{"*", "TypeNameAsterisk", false},
    17  		{"0", "TypeNameZero", false},
    18  		{"8.3", "TypeName_8_3", false},
    19  		{"11", "TypeName_11", false},
    20  		{"Microsoft-Windows-Shell-Startup", "TypeName_Microsoft_Windows_Shell_Startup", false},
    21  		{"Microsoft.Batch", "TypeName_Microsoft_Batch", false},
    22  		{"readonly", "TypeNameReadonly", false},
    23  		{"SystemAssigned, UserAssigned", "TypeName_SystemAssigned_UserAssigned", false},
    24  		{"Dev(NoSLA)_Standard_D11_v2", "TypeName_Dev_NoSLA_Standard_D11_v2", false},
    25  		{"Standard_E8as_v4+1TB_PS", "TypeName_Standard_E8as_v4_1TB_PS", false},
    26  	}
    27  	//nolint:paralleltest // false positive because range var isn't used directly in t.Run(name) arg
    28  	for _, tt := range tests {
    29  		tt := tt
    30  		t.Run(tt.input, func(t *testing.T) {
    31  			t.Parallel()
    32  
    33  			got, err := makeSafeEnumName(tt.input, "TypeName")
    34  			if (err != nil) != tt.wantErr {
    35  				t.Errorf("makeSafeEnumName() error = %v, wantErr %v", err, tt.wantErr)
    36  				return
    37  			}
    38  			if got != tt.expected {
    39  				t.Errorf("makeSafeEnumName() got = %v, want %v", got, tt.expected)
    40  			}
    41  		})
    42  	}
    43  }
    44  
    45  func Test_makeValidIdentifier(t *testing.T) {
    46  	t.Parallel()
    47  	tests := []struct {
    48  		input    string
    49  		expected string
    50  	}{
    51  		{"&opts0", "&opts0"},
    52  		{"8", "_8"},
    53  	}
    54  	for _, tt := range tests {
    55  		tt := tt
    56  		t.Run(tt.input, func(t *testing.T) {
    57  			t.Parallel()
    58  			if got := makeValidIdentifier(tt.input); got != tt.expected {
    59  				t.Errorf("makeValidIdentifier() = %v, want %v", got, tt.expected)
    60  			}
    61  		})
    62  	}
    63  }