-
Notifications
You must be signed in to change notification settings - Fork 116
Core Test Function #2762
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
Merged
Merged
Core Test Function #2762
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package deploy | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/tests/e2e/commandse2e" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/tests/e2e/commands" | ||
| ginkgo "github.com/onsi/ginkgo/v2" | ||
| "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| const ( | ||
| subnetName = "testSubnet" | ||
| ) | ||
|
|
||
| var ( | ||
| err error | ||
| ) | ||
|
|
||
| const ewoqEVMAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC" | ||
|
|
||
| var _ = ginkgo.Describe("[Blockchain Deploy Flags]", ginkgo.Ordered, func() { | ||
| _ = ginkgo.BeforeEach(func() { | ||
| // Create test subnet config | ||
| commands.CreateEtnaSubnetEvmConfig(subnetName, ewoqEVMAddress, commands.PoA) | ||
| }) | ||
|
|
||
| ginkgo.AfterEach(func() { | ||
| commands.CleanNetwork() | ||
| // Cleanup test subnet config | ||
| commands.DeleteSubnetConfig(subnetName) | ||
| }) | ||
| blockchainCmdArgs := []string{subnetName} | ||
| ginkgo.It("HAPPY PATH: local deploy default", func() { | ||
| testFlags := commandse2e.TestFlags{} | ||
| output, err := commandse2e.TestCommand(commandse2e.BlockchainCmd, "deploy", blockchainCmdArgs, testFlags) | ||
| gomega.Expect(output).Should(gomega.ContainSubstring("L1 is successfully deployed on Local Network")) | ||
| gomega.Expect(err).Should(gomega.BeNil()) | ||
| }) | ||
|
|
||
| ginkgo.It("ERROR PATH: invalid_version", func() { | ||
| testFlags := commandse2e.TestFlags{ | ||
| "avalanchego-version": "invalid_version", | ||
| } | ||
| output, err := commandse2e.TestCommand(commandse2e.BlockchainCmd, "deploy", blockchainCmdArgs, testFlags) | ||
| fmt.Printf("obtained output %s \n", string(output)) | ||
| gomega.Expect(err).Should(gomega.HaveOccurred()) | ||
| gomega.Expect(output).Should(gomega.ContainSubstring("invalid version string")) | ||
| }) | ||
| }) | ||
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,74 @@ | ||
| // Copyright (C) 2022, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
| package commandse2e | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os/exec" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/tests/e2e/utils" | ||
| ) | ||
|
|
||
| type TestFlags map[string]string | ||
|
|
||
| // CommandGroup represents the different command groups available in the CLI | ||
| type CommandGroup string | ||
|
|
||
| const ( | ||
| BlockchainCmd CommandGroup = "blockchain" | ||
| ) | ||
|
|
||
| var avalancheBinaryPath = "./bin/avalanche" | ||
|
|
||
| var GlobalFlags = map[string]interface{}{ | ||
| "local": true, | ||
| "skip-icm-deploy": true, | ||
| "skip-update-check": true, | ||
| } | ||
|
|
||
| // TestCommand tests a CLI command with flag inputs | ||
| func TestCommand(commandGroup CommandGroup, command string, args []string, testFlags TestFlags) (string, error) { | ||
|
Contributor
Author
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. core test function |
||
| // Build command arguments | ||
| cmdArgs := []string{string(commandGroup), command} | ||
|
|
||
| // Append any additional arguments | ||
| if len(args) > 0 { | ||
| cmdArgs = append(cmdArgs, args...) | ||
| } | ||
|
|
||
| // Create a map to store all flags, starting with global flags | ||
| allFlags := make(map[string]interface{}) | ||
| for flag, value := range GlobalFlags { | ||
| allFlags[flag] = value | ||
| } | ||
|
|
||
| // Override with test case specific flags if provided | ||
| for flag, value := range testFlags { | ||
| allFlags[flag] = value | ||
| } | ||
|
|
||
| // Add all flags to command arguments | ||
| for flag, value := range allFlags { | ||
| cmdArgs = append(cmdArgs, "--"+flag+"="+fmt.Sprintf("%v", value)) | ||
| } | ||
|
|
||
| // Execute the command | ||
| cmd := exec.Command(avalancheBinaryPath, cmdArgs...) | ||
| fmt.Println(cmd) | ||
| output, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| var ( | ||
| exitErr *exec.ExitError | ||
| stderr string | ||
| ) | ||
| if errors.As(err, &exitErr) { | ||
| stderr = string(exitErr.Stderr) | ||
| } | ||
| fmt.Println(string(output)) | ||
| utils.PrintStdErr(err) | ||
| fmt.Println(stderr) | ||
| } | ||
|
|
||
| return string(output), err | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of how to use it