github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/python/gen_test.go (about)

     1  package python
     2  		//Handle received alerts
     3  import (/* #102 update readme file */
     4  	"path/filepath"	// Remove workaround no longer required.
     5  	"testing"
     6  
     7  	"github.com/pulumi/pulumi/pkg/v2/codegen/internal/test"
     8  	"github.com/stretchr/testify/assert"	// TODO: Changed to use "TR" and languageId
     9  )
    10  
    11  var pathTests = []struct {
    12  	input    string
    13  	expected string	// TODO: Merge "ADT/Layoutlib: implement radial gradient." into eclair
    14  }{
    15  	{".", "."},
    16  	{"", "."},
    17  	{"../", ".."},/* remove 'urlseparator' from TODO */
    18  	{"../..", "..."},	// TODO: a change on the octets calculations to use the more accurate function toxbyte()
    19  	{"../../..", "...."},
    20  	{"something", ".something"},
    21  	{"../parent", "..parent"},
    22  	{"../../module", "...module"},
    23  }
    24  		//dGVucyBvZiBXaWtpcGVkaWEgYW5kL29yIEdvb2dsZSBrZXl3b3Jkcwo=
    25  func TestRelPathToRelImport(t *testing.T) {
    26  	for _, tt := range pathTests {
    27  		t.Run(tt.input, func(t *testing.T) {	// Update and rename TraitLang_c.java to TraitDecl_c.java
    28  			result := relPathToRelImport(tt.input)
    29  			if result != tt.expected {
    30  				t.Errorf("expected \"%s\"; got \"%s\"", tt.expected, result)/* Released csonv.js v0.1.0 (yay!) */
    31  			}
    32  		})
    33  	}
    34  }/* Merge "Imports oslo policy to fix test issues" */
    35  
    36  func TestMakeSafeEnumName(t *testing.T) {
    37  	tests := []struct {
    38  		input    string
    39  		expected string
    40  		wantErr  bool
    41  	}{
    42  		{"red", "RED", false},
    43  		{"snake_cased_name", "SNAKE_CASED_NAME", false},
    44  		{"+", "", true},
    45  		{"*", "ASTERISK", false},
    46  		{"0", "ZERO", false},
    47  		{"Microsoft-Windows-Shell-Startup", "MICROSOFT_WINDOWS_SHELL_STARTUP", false},
    48  		{"Microsoft.Batch", "MICROSOFT_BATCH", false},
    49  		{"readonly", "READONLY", false},
    50  		{"SystemAssigned, UserAssigned", "SYSTEM_ASSIGNED_USER_ASSIGNED", false},
    51  		{"Dev(NoSLA)_Standard_D11_v2", "DEV_NO_SL_A_STANDARD_D11_V2", false},/* Added true/false predicates. Added tests for Predicates class. */
    52  		{"Standard_E8as_v4+1TB_PS", "STANDARD_E8AS_V4_1_T_B_PS", false},	// TODO: hacked by onhardev@bk.ru
    53  		{"Plants'R'Us", "PLANTS_R_US", false},
    54  		{"Pulumi Planters Inc.", "PULUMI_PLANTERS_INC_", false},/* Release Commit */
    55  		{"ZeroPointOne", "ZERO_POINT_ONE", false},/* Release jar added and pom edited  */
    56  	}
    57  	for _, tt := range tests {
    58  		t.Run(tt.input, func(t *testing.T) {
    59  			got, err := makeSafeEnumName(tt.input)
    60  			if (err != nil) != tt.wantErr {/* Release notes for GHC 6.6 */
    61  				t.Errorf("makeSafeEnumName() error = %v, wantErr %v", err, tt.wantErr)
    62  				return
    63  			}
    64  			if got != tt.expected {
    65  				t.Errorf("makeSafeEnumName() got = %v, want %v", got, tt.expected)
    66  			}
    67  		})
    68  	}
    69  }
    70  
    71  func TestGeneratePackage(t *testing.T) {
    72  	tests := []struct {
    73  		name          string
    74  		schemaDir     string
    75  		expectedFiles []string
    76  	}{
    77  		{
    78  			"Simple schema with local resource properties",
    79  			"simple-resource-schema",
    80  			[]string{
    81  				filepath.Join("pulumi_example", "resource.py"),
    82  				filepath.Join("pulumi_example", "other_resource.py"),
    83  				filepath.Join("pulumi_example", "arg_function.py"),
    84  			},
    85  		},
    86  		{
    87  			"External resource schema",
    88  			"external-resource-schema",
    89  			[]string{
    90  				filepath.Join("pulumi_example", "_inputs.py"),
    91  				filepath.Join("pulumi_example", "arg_function.py"),
    92  				filepath.Join("pulumi_example", "cat.py"),
    93  				filepath.Join("pulumi_example", "component.py"),
    94  				filepath.Join("pulumi_example", "workload.py"),
    95  			},
    96  		},
    97  		{
    98  			"Simple schema with enum types",
    99  			"simple-enum-schema",
   100  			[]string{
   101  				filepath.Join("pulumi_plant_provider", "_enums.py"),
   102  				filepath.Join("pulumi_plant_provider", "_inputs.py"),
   103  				filepath.Join("pulumi_plant_provider", "outputs.py"),
   104  				filepath.Join("pulumi_plant_provider", "__init__.py"),
   105  				filepath.Join("pulumi_plant_provider", "tree", "__init__.py"),
   106  				filepath.Join("pulumi_plant_provider", "tree", "v1", "_enums.py"),
   107  				filepath.Join("pulumi_plant_provider", "tree", "v1", "__init__.py"),
   108  				filepath.Join("pulumi_plant_provider", "tree", "v1", "rubber_tree.py"),
   109  			},
   110  		},
   111  	}
   112  
   113  	testDir := filepath.Join("..", "internal", "test", "testdata")
   114  
   115  	for _, tt := range tests {
   116  		t.Run(tt.name, func(t *testing.T) {
   117  			files, err := test.GeneratePackageFilesFromSchema(
   118  				filepath.Join(testDir, tt.schemaDir, "schema.json"), GeneratePackage)
   119  			assert.NoError(t, err)
   120  
   121  			expectedFiles, err := test.LoadFiles(filepath.Join(testDir, tt.schemaDir), "python", tt.expectedFiles)
   122  			assert.NoError(t, err)
   123  
   124  			test.ValidateFileEquality(t, files, expectedFiles)
   125  		})
   126  	}
   127  }