|
| 1 | +package testhelpers_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + temporaliov1alpha1 "github.com/temporalio/temporal-worker-controller/api/v1alpha1" |
| 10 | + "github.com/temporalio/temporal-worker-controller/internal/testhelpers" |
| 11 | +) |
| 12 | + |
| 13 | +// ExampleTestCase demonstrates how to create and use a TestCase for integration testing. |
| 14 | +// This example shows the basic structure and usage patterns for TestCase. |
| 15 | +func ExampleTestCase() { |
| 16 | + // Create a test case using the builder pattern |
| 17 | + testCaseBuilder := testhelpers.NewTestCase(). |
| 18 | + WithInput( |
| 19 | + testhelpers.NewTemporalWorkerDeploymentBuilder(). |
| 20 | + WithName("example-worker"). |
| 21 | + WithNamespace("default"). |
| 22 | + WithManualStrategy(). |
| 23 | + WithTargetTemplate("v1"), |
| 24 | + ). |
| 25 | + WithExpectedStatus( |
| 26 | + testhelpers.NewStatusBuilder(). |
| 27 | + WithTargetVersion("v1", temporaliov1alpha1.VersionStatusInactive, -1, true, false), |
| 28 | + ). |
| 29 | + WithWaitTime(5 * time.Second). |
| 30 | + WithSetupFunction(func(t *testing.T, ctx context.Context, tc testhelpers.TestCase, env testhelpers.TestEnv) { |
| 31 | + // Custom setup logic can go here |
| 32 | + fmt.Println("Setting up test environment") |
| 33 | + }) |
| 34 | + |
| 35 | + testCase := testCaseBuilder.BuildWithValues("example-worker", "default", "default") |
| 36 | + |
| 37 | + // Access the TestCase fields |
| 38 | + twd := testCase.GetTWD() |
| 39 | + fmt.Printf("Testing deployment: %s/%s\n", twd.Namespace, twd.Name) |
| 40 | + fmt.Printf("Strategy: %s\n", twd.Spec.RolloutStrategy.Strategy) |
| 41 | + |
| 42 | + // Output: |
| 43 | + // Testing deployment: default/example-worker |
| 44 | + // Strategy: Manual |
| 45 | +} |
| 46 | + |
| 47 | +// ExampleTestCase_withExistingDeployments demonstrates how to create a TestCase |
| 48 | +// that starts with existing deprecated deployments. |
| 49 | +func ExampleTestCase_withExistingDeployments() { |
| 50 | + testCaseBuilder := testhelpers.NewTestCase(). |
| 51 | + WithInput( |
| 52 | + testhelpers.NewTemporalWorkerDeploymentBuilder(). |
| 53 | + WithName("worker-with-history"). |
| 54 | + WithNamespace("test-ns"). |
| 55 | + WithAllAtOnceStrategy(). |
| 56 | + WithTargetTemplate("v2"), |
| 57 | + ). |
| 58 | + WithExistingDeployments(testhelpers.DeploymentInfo{}). |
| 59 | + WithExpectedStatus( |
| 60 | + testhelpers.NewStatusBuilder(). |
| 61 | + WithTargetVersion("v2", temporaliov1alpha1.VersionStatusInactive, -1, true, false), |
| 62 | + ) |
| 63 | + |
| 64 | + testCase := testCaseBuilder.BuildWithValues("worker-with-history", "test-ns", "default") |
| 65 | + |
| 66 | + twd := testCase.GetTWD() |
| 67 | + fmt.Printf("Worker: %s/%s\n", twd.Namespace, twd.Name) |
| 68 | + |
| 69 | + // Output: |
| 70 | + // Worker: test-ns/worker-with-history |
| 71 | +} |
0 commit comments