-
Notifications
You must be signed in to change notification settings - Fork 116
Deploy flags e2e #2755
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
Closed
Closed
Deploy flags e2e #2755
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
afbba82
deploy flags e2e
sukantoraymond 6a6fb04
deploy flags e2e
sukantoraymond 7a7ec4f
use evm address
sukantoraymond f22428f
fix lint
sukantoraymond e491435
rename tests
sukantoraymond 0c7e5df
remove duplicate
sukantoraymond f8f9225
make test function general
sukantoraymond b2f2222
lint
sukantoraymond a741643
lint
sukantoraymond 47f4a46
lint
sukantoraymond 12c704f
lint
sukantoraymond 438fe47
add output
sukantoraymond abdc06a
add more testcases
sukantoraymond 23bb74c
add more test cases
sukantoraymond 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,111 @@ | ||
| package blockchain | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/tests/e2e/utils" | ||
| ) | ||
|
|
||
| // TestCase represents a single test case configuration | ||
| type TestCase struct { | ||
| Name string `json:"name"` | ||
| Flags map[string]string `json:"flags"` | ||
| ExpectedError string `json:"expectedError,omitempty"` | ||
| } | ||
|
|
||
| // TestJSONConfig represents the json configuration that contains cli command flag inputs | ||
| type TestJSONConfig struct { | ||
| GlobalFlags map[string]interface{} `json:"globalFlags"` | ||
| HappyPath []TestCase `json:"happyPath"` | ||
| NotHappyPath []TestCase `json:"notHappyPath"` | ||
| } | ||
|
|
||
| var avalancheBinaryPath = "./bin/avalanche" | ||
|
|
||
| // SetAvalancheBinaryPath sets the path to the avalanche binary | ||
| func SetAvalancheBinaryPath(path string) { | ||
| avalancheBinaryPath = path | ||
| } | ||
|
|
||
| // TestCommandWithJSONConfig tests a CLI command with flag inputs from a JSON file | ||
| func TestCommandWithJSONConfig(command string, configPath string, testCase *TestCase) (string, error) { | ||
| blockchainCmd := "blockchain" | ||
|
|
||
| // Read and parse the JSON config file | ||
| configData, err := os.ReadFile(configPath) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to read config file: %w", err) | ||
| } | ||
|
|
||
| var config TestJSONConfig | ||
| if err := json.Unmarshal(configData, &config); err != nil { | ||
| return "", fmt.Errorf("failed to parse config file: %w", err) | ||
| } | ||
|
|
||
| // Build command arguments | ||
| cmdArgs := []string{blockchainCmd, command} | ||
|
|
||
| // Add blockchain name from global flags | ||
| if blockchainName, ok := config.GlobalFlags["blockchainName"].(string); ok { | ||
| cmdArgs = append(cmdArgs, blockchainName) | ||
| } | ||
|
|
||
| // Create a map to store all flags, starting with global flags | ||
| allFlags := make(map[string]interface{}) | ||
| for flag, value := range config.GlobalFlags { | ||
| if flag != "blockchainName" { | ||
| allFlags[flag] = value | ||
| } | ||
| } | ||
|
|
||
| // Override with test case specific flags if provided | ||
| if testCase != nil { | ||
| for flag, value := range testCase.Flags { | ||
| 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 "", err | ||
| } | ||
|
|
||
| return string(output), nil | ||
| } | ||
|
|
||
| // ReadTestConfig reads and parses the test configuration from a JSON file | ||
| func ReadTestConfig(configPath string) (*TestJSONConfig, error) { | ||
| configData, err := os.ReadFile(configPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read config file: %w", err) | ||
| } | ||
|
|
||
| var config TestJSONConfig | ||
| if err := json.Unmarshal(configData, &config); err != nil { | ||
| return nil, fmt.Errorf("failed to parse config file: %w", err) | ||
| } | ||
|
|
||
| return &config, nil | ||
| } | ||
111 changes: 111 additions & 0 deletions
111
tests/e2e/commands_e2e/blockchain/blockchain_command.go
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,111 @@ | ||
| package blockchain | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/tests/e2e/utils" | ||
| ) | ||
|
|
||
| // TestCase represents a single test case configuration | ||
| type TestCase struct { | ||
| Name string `json:"name"` | ||
| Flags map[string]string `json:"flags"` | ||
| ExpectedError string `json:"expectedError,omitempty"` | ||
| } | ||
|
|
||
| // TestJSONConfig represents the json configuration that contains cli command flag inputs | ||
| type TestJSONConfig struct { | ||
| GlobalFlags map[string]interface{} `json:"globalFlags"` | ||
| HappyPath []TestCase `json:"happyPath"` | ||
| NotHappyPath []TestCase `json:"notHappyPath"` | ||
| } | ||
|
|
||
| var avalancheBinaryPath = "./bin/avalanche" | ||
|
|
||
| // SetAvalancheBinaryPath sets the path to the avalanche binary | ||
| func SetAvalancheBinaryPath(path string) { | ||
| avalancheBinaryPath = path | ||
| } | ||
|
|
||
| // TestCommandWithJSONConfig tests a CLI command with flag inputs from a JSON file | ||
| func TestCommandWithJSONConfig(command string, configPath string, testCase *TestCase) (string, error) { | ||
| blockchainCmd := "blockchain" | ||
|
|
||
| // Read and parse the JSON config file | ||
| configData, err := os.ReadFile(configPath) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to read config file: %w", err) | ||
| } | ||
|
|
||
| var config TestJSONConfig | ||
| if err := json.Unmarshal(configData, &config); err != nil { | ||
| return "", fmt.Errorf("failed to parse config file: %w", err) | ||
| } | ||
|
|
||
| // Build command arguments | ||
| cmdArgs := []string{blockchainCmd, command} | ||
|
|
||
| // Add blockchain name from global flags | ||
| if blockchainName, ok := config.GlobalFlags["blockchainName"].(string); ok { | ||
| cmdArgs = append(cmdArgs, blockchainName) | ||
| } | ||
|
|
||
| // Create a map to store all flags, starting with global flags | ||
| allFlags := make(map[string]interface{}) | ||
| for flag, value := range config.GlobalFlags { | ||
| if flag != "blockchainName" { | ||
| allFlags[flag] = value | ||
| } | ||
| } | ||
|
|
||
| // Override with test case specific flags if provided | ||
| if testCase != nil { | ||
| for flag, value := range testCase.Flags { | ||
| 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 "", err | ||
| } | ||
|
|
||
| return string(output), nil | ||
| } | ||
|
|
||
| // ReadTestConfig reads and parses the test configuration from a JSON file | ||
| func ReadTestConfig(configPath string) (*TestJSONConfig, error) { | ||
| configData, err := os.ReadFile(configPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read config file: %w", err) | ||
| } | ||
|
|
||
| var config TestJSONConfig | ||
| if err := json.Unmarshal(configData, &config); err != nil { | ||
| return nil, fmt.Errorf("failed to parse config file: %w", err) | ||
| } | ||
|
|
||
| return &config, nil | ||
| } |
23 changes: 23 additions & 0 deletions
23
tests/e2e/commands_e2e/blockchain/deploy/deploy_tests.json
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,23 @@ | ||
| { | ||
| "globalFlags": { | ||
| "local": true, | ||
| "skip-icm-deploy": true, | ||
| "skip-update-check": true, | ||
| "blockchainName": "testSubnet" | ||
| }, | ||
| "happyPath": [ | ||
| { | ||
| "name": "local_deploy", | ||
| "flags": {} | ||
| } | ||
|
||
| ], | ||
| "notHappyPath": [ | ||
| { | ||
| "name": "invalid_version", | ||
| "flags": { | ||
| "avalanchego-version": "invalid_version" | ||
| }, | ||
| "expectedError": "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,66 @@ | ||
| // 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/commands" | ||
| "github.com/ava-labs/avalanche-cli/tests/e2e/commands_e2e/blockchain" | ||
| "github.com/ava-labs/avalanche-cli/tests/e2e/utils" | ||
| ginkgo "github.com/onsi/ginkgo/v2" | ||
| "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| const ( | ||
| deployTestJsonPath = "tests/e2e/commands_e2e/blockchain/deploy/deploy_tests.json" | ||
| subnetName = "testSubnet" | ||
| ) | ||
|
|
||
| var ( | ||
| config *blockchain.TestJSONConfig | ||
| err error | ||
| ) | ||
|
|
||
| var _ = ginkgo.Describe("[Blockchain Deploy Flags]", ginkgo.Ordered, func() { | ||
| _ = ginkgo.BeforeEach(func() { | ||
| // Create test subnet config | ||
| commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPath) | ||
|
|
||
| // Read test configuration | ||
| config, err = blockchain.ReadTestConfig(deployTestJsonPath) | ||
| gomega.Expect(err).Should(gomega.BeNil()) | ||
| }) | ||
|
|
||
| ginkgo.AfterEach(func() { | ||
| commands.CleanNetwork() | ||
| // Cleanup test subnet config | ||
| commands.DeleteSubnetConfig(subnetName) | ||
| }) | ||
|
|
||
| ginkgo.It("should successfully deploy a blockchain", func() { | ||
| // Run each happy path test case | ||
| for _, testCase := range config.HappyPath { | ||
| ginkgo.By(fmt.Sprintf("Running test case: %s", testCase.Name)) | ||
| _, err = blockchain.TestCommandWithJSONConfig( | ||
| "deploy", | ||
| deployTestJsonPath, | ||
| &testCase, | ||
| ) | ||
| gomega.Expect(err).Should(gomega.BeNil()) | ||
| } | ||
| }) | ||
|
|
||
| ginkgo.It("should handle invalid configurations", func() { | ||
| // Run each not happy path test case | ||
| for _, testCase := range config.NotHappyPath { | ||
| ginkgo.By(fmt.Sprintf("Running test case: %s", testCase.Name)) | ||
| _, err = blockchain.TestCommandWithJSONConfig( | ||
| "deploy", | ||
| deployTestJsonPath, | ||
| &testCase, | ||
| ) | ||
| gomega.Expect(err).Should(gomega.HaveOccurred()) | ||
| } | ||
| }) | ||
| }) | ||
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.
love the idea - any plan to move it to some test common directories to enable it reusable by all other commands?
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.
Thanks! Yes i will move it to external directories
Uh oh!
There was an error while loading. Please reload this page.
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.
Generalized the function