|
| 1 | +package opttest_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "path/filepath" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/pulumi/providertest/pulumitest/opttest" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPythonLinkOption(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + opts := opttest.DefaultOptions() |
| 15 | + assert.Empty(t, opts.PythonLinks, "expected PythonLinks to be empty by default") |
| 16 | + |
| 17 | + pythonLink := opttest.PythonLink("path/to/sdk") |
| 18 | + pythonLink.Apply(opts) |
| 19 | + |
| 20 | + assert.Equal(t, []string{"path/to/sdk"}, opts.PythonLinks, "expected PythonLink to append path") |
| 21 | +} |
| 22 | + |
| 23 | +func TestPythonLinkMultiplePackages(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + |
| 26 | + opts := opttest.DefaultOptions() |
| 27 | + |
| 28 | + pythonLink := opttest.PythonLink("path/to/sdk1", "path/to/sdk2") |
| 29 | + pythonLink.Apply(opts) |
| 30 | + |
| 31 | + assert.Equal(t, []string{"path/to/sdk1", "path/to/sdk2"}, opts.PythonLinks, |
| 32 | + "expected PythonLink to append multiple paths") |
| 33 | +} |
| 34 | + |
| 35 | +func TestPythonLinkAccumulates(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + |
| 38 | + opts := opttest.DefaultOptions() |
| 39 | + |
| 40 | + pythonLink1 := opttest.PythonLink("path/to/sdk1") |
| 41 | + pythonLink1.Apply(opts) |
| 42 | + |
| 43 | + pythonLink2 := opttest.PythonLink("path/to/sdk2") |
| 44 | + pythonLink2.Apply(opts) |
| 45 | + |
| 46 | + assert.Equal(t, []string{"path/to/sdk1", "path/to/sdk2"}, opts.PythonLinks, |
| 47 | + "expected PythonLinks to accumulate across multiple calls") |
| 48 | +} |
| 49 | + |
| 50 | +func TestDefaultsResetsPythonLinks(t *testing.T) { |
| 51 | + t.Parallel() |
| 52 | + |
| 53 | + opts := opttest.DefaultOptions() |
| 54 | + |
| 55 | + pythonLink := opttest.PythonLink("path/to/sdk") |
| 56 | + pythonLink.Apply(opts) |
| 57 | + |
| 58 | + assert.NotEmpty(t, opts.PythonLinks, "expected PythonLinks to be populated") |
| 59 | + |
| 60 | + defaults := opttest.Defaults() |
| 61 | + defaults.Apply(opts) |
| 62 | + |
| 63 | + assert.Empty(t, opts.PythonLinks, "expected Defaults to reset PythonLinks") |
| 64 | +} |
| 65 | + |
| 66 | +func TestPythonLinkIntegrationV1(t *testing.T) { |
| 67 | + t.Parallel() |
| 68 | + |
| 69 | + // Integration test: verify PythonLink can be used with a real test package (v1) |
| 70 | + // This test checks that the option correctly processes package paths |
| 71 | + pkgV1Path := filepath.Join("..", "testdata", "python_pkg_v1") |
| 72 | + |
| 73 | + // Verify the test package directory exists |
| 74 | + _, err := filepath.Abs(pkgV1Path) |
| 75 | + assert.NoError(t, err, "expected to resolve package path v1") |
| 76 | + |
| 77 | + // Create test with PythonLink pointing to v1 package |
| 78 | + opts := opttest.DefaultOptions() |
| 79 | + pythonLink := opttest.PythonLink(pkgV1Path) |
| 80 | + pythonLink.Apply(opts) |
| 81 | + |
| 82 | + // Verify the path was correctly added to options |
| 83 | + assert.Equal(t, 1, len(opts.PythonLinks), "expected one Python package path") |
| 84 | + assert.True(t, len(opts.PythonLinks[0]) > 0, "expected non-empty package path") |
| 85 | +} |
| 86 | + |
| 87 | +func TestPythonLinkIntegrationV2(t *testing.T) { |
| 88 | + t.Parallel() |
| 89 | + |
| 90 | + // Integration test: verify PythonLink can be used with a real test package (v2) |
| 91 | + pkgV2Path := filepath.Join("..", "testdata", "python_pkg_v2") |
| 92 | + |
| 93 | + // Verify the test package directory exists |
| 94 | + _, err := filepath.Abs(pkgV2Path) |
| 95 | + assert.NoError(t, err, "expected to resolve package path v2") |
| 96 | + |
| 97 | + // Create test with PythonLink pointing to v2 package |
| 98 | + opts := opttest.DefaultOptions() |
| 99 | + pythonLink := opttest.PythonLink(pkgV2Path) |
| 100 | + pythonLink.Apply(opts) |
| 101 | + |
| 102 | + // Verify the path was correctly added to options |
| 103 | + assert.Equal(t, 1, len(opts.PythonLinks), "expected one Python package path") |
| 104 | + assert.True(t, len(opts.PythonLinks[0]) > 0, "expected non-empty package path") |
| 105 | +} |
| 106 | + |
| 107 | +func TestPythonLinkUpgradePathGeneration(t *testing.T) { |
| 108 | + t.Parallel() |
| 109 | + |
| 110 | + // Integration test: verify PythonLink generates correct paths for version upgrades |
| 111 | + pkgV1Path := filepath.Join("..", "testdata", "python_pkg_v1") |
| 112 | + pkgV2Path := filepath.Join("..", "testdata", "python_pkg_v2") |
| 113 | + |
| 114 | + opts := opttest.DefaultOptions() |
| 115 | + |
| 116 | + // Add v1 package |
| 117 | + pythonLinkV1 := opttest.PythonLink(pkgV1Path) |
| 118 | + pythonLinkV1.Apply(opts) |
| 119 | + assert.Equal(t, 1, len(opts.PythonLinks), "expected one path after v1") |
| 120 | + |
| 121 | + // Add v2 package (simulating version upgrade) |
| 122 | + pythonLinkV2 := opttest.PythonLink(pkgV2Path) |
| 123 | + pythonLinkV2.Apply(opts) |
| 124 | + assert.Equal(t, 2, len(opts.PythonLinks), "expected two paths after adding v2") |
| 125 | + |
| 126 | + // Verify both paths are present |
| 127 | + assert.Contains(t, opts.PythonLinks, pkgV1Path, "expected v1 path to be present") |
| 128 | + assert.Contains(t, opts.PythonLinks, pkgV2Path, "expected v2 path to be present") |
| 129 | +} |
0 commit comments