generated from konveyor/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 7
🧪 add tests/ infra
#51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
midays
wants to merge
7
commits into
konveyor-ecosystem:main
Choose a base branch
from
midays:add-e2e-test-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05d76d8
Update dependencies and add end-to-end tests for export command
midays e33e369
Refactor testing framework and enhance end-to-end tests
midays 6e65739
Add test configuration template and refactor cluster management
midays 2a6973e
Refactor cluster utility functions and relocate string containment check
midays da30d93
Add config.yaml existence check in test setup
midays dc96af5
Enhance test setup and error handling for configuration loading
midays 82576cf
Merge branch 'konveyor-ecosystem:main' into add-e2e-test-setup
midays File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package export_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/konveyor-ecosystem/kubectl-migrate/test/utils" | ||
| ) | ||
|
|
||
| var _ = Describe("Export Command", func() { | ||
| var ( | ||
| testNamespace string | ||
| exportDir string | ||
| appName string | ||
| ) | ||
|
|
||
| // BeforeAll runs ONCE before all tests in this suite | ||
| BeforeAll(func() { | ||
| GinkgoWriter.Println("Checking kind cluster connectivity...") | ||
|
|
||
| // Check if we can connect to a kind cluster | ||
| err := utils.CheckKindCluster("kind") | ||
| Expect(err).NotTo(HaveOccurred(), "Should be able to connect to kind cluster") | ||
|
|
||
| GinkgoWriter.Println("✓ Kind cluster is accessible") | ||
| }) | ||
|
|
||
| // BeforeEach runs before EACH test | ||
| BeforeEach(func() { | ||
| testNamespace = "test-export-ns" | ||
| appName = "test-nginx" | ||
| exportDir = filepath.Join(os.TempDir(), "kubectl-migrate-export-test") | ||
|
|
||
| GinkgoWriter.Printf("Setting up test namespace: %s\n", testNamespace) | ||
|
|
||
| // Create test namespace | ||
| err := utils.CreateNamespace(testNamespace) | ||
| Expect(err).NotTo(HaveOccurred(), "Should create namespace successfully") | ||
|
|
||
| GinkgoWriter.Println("✓ Namespace created") | ||
|
|
||
| // Deploy test application | ||
| GinkgoWriter.Printf("Deploying test app: %s\n", appName) | ||
| err = utils.DeployTestApp(testNamespace, appName) | ||
| Expect(err).NotTo(HaveOccurred(), "Should deploy test app successfully") | ||
|
|
||
| GinkgoWriter.Println("✓ Test app deployed") | ||
|
|
||
| // Create export directory | ||
| err = os.MkdirAll(exportDir, 0755) | ||
| Expect(err).NotTo(HaveOccurred(), "Should create export directory") | ||
|
|
||
| GinkgoWriter.Printf("✓ Export directory created: %s\n", exportDir) | ||
| }) | ||
|
|
||
| // AfterEach runs after EACH test | ||
| AfterEach(func() { | ||
| GinkgoWriter.Println("Cleaning up...") | ||
|
|
||
| // Remove export directory | ||
| if exportDir != "" { | ||
| err := os.RemoveAll(exportDir) | ||
| Expect(err).NotTo(HaveOccurred(), "Should remove export directory") | ||
| GinkgoWriter.Println("✓ Export directory removed") | ||
| } | ||
|
|
||
| // Delete test namespace | ||
| if testNamespace != "" { | ||
| err := utils.DeleteNamespace(testNamespace) | ||
| Expect(err).NotTo(HaveOccurred(), "Should delete namespace") | ||
| GinkgoWriter.Printf("✓ Namespace %s deleted\n", testNamespace) | ||
| } | ||
| }) | ||
|
|
||
| Context("Basic Export Test", func() { | ||
| It("should successfully export resources from a namespace", func() { | ||
| GinkgoWriter.Printf("Running export command for namespace: %s\n", testNamespace) | ||
|
|
||
| // Run the kubectl migrate export command | ||
| result := utils.RunCommand("kubectl", "migrate", "export", | ||
| testNamespace, | ||
| "--export-dir", exportDir) | ||
|
|
||
| // Verify command succeeded | ||
| GinkgoWriter.Printf("Command output:\n%s\n", result.String()) | ||
| Expect(result.Success()).To(BeTrue(), "Export command should succeed") | ||
|
|
||
| // Verify export directory contains files | ||
| files, err := os.ReadDir(exportDir) | ||
| Expect(err).NotTo(HaveOccurred(), "Should be able to read export directory") | ||
| Expect(files).NotTo(BeEmpty(), "Export directory should contain files") | ||
|
|
||
| GinkgoWriter.Printf("✓ Exported %d files\n", len(files)) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Export Command E2E Tests | ||
|
|
||
| This directory contains end-to-end tests for the `kubectl migrate export` command. | ||
|
|
||
| ## Test Scenarios | ||
|
|
||
| ### 1. Basic Export Test | ||
| **Objective:** Verify that the export command successfully exports resources from a namespace | ||
|
|
||
| **Test Steps:** | ||
| 1. Set up a test Kubernetes cluster with sample resources | ||
| 2. Create a test namespace with sample deployments, services, and configmaps | ||
| 3. Run `kubectl migrate export <namespace> --export-dir <temp-dir>` | ||
| 4. Verify that: | ||
| - Export directory is created | ||
| - Resource YAML files are exported | ||
| - All expected resource types are present | ||
| - File contents are valid YAML | ||
|
|
||
| **Expected Result:** All resources from the namespace are exported to the specified directory | ||
|
|
||
| ### 2. Export with Invalid Namespace | ||
| **Objective:** Verify proper error handling when namespace doesn't exist | ||
|
|
||
| **Test Steps:** | ||
| 1. Run `kubectl migrate export non-existent-namespace --export-dir <temp-dir>` | ||
| 2. Verify that: | ||
| - Command returns an error | ||
| - Error message is informative | ||
| - No files are created | ||
|
|
||
| **Expected Result:** Command fails gracefully with appropriate error message | ||
|
|
||
| ### 3. Export with Custom Kubeconfig | ||
| **Objective:** Verify export works with custom kubeconfig file | ||
|
|
||
| **Test Steps:** | ||
| 1. Create a custom kubeconfig file | ||
| 2. Run `kubectl migrate export <namespace> --kubeconfig <custom-config> --export-dir <temp-dir>` | ||
| 3. Verify successful export using the specified kubeconfig | ||
|
|
||
| **Expected Result:** Resources are exported using the custom kubeconfig | ||
|
|
||
| ## Test Data | ||
|
|
||
| - Sample deployments: nginx, redis | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question, do these deployments come from sample resources? (not sure about |
||
| - Sample services: nginx-service, redis-service | ||
| - Sample configmaps: app-config | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Kind or Minikube cluster running | ||
| - Sample resources deployed (use `make resources-deploy`) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package e2e_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestE2e(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "E2e Suite") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.