forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert local testing changes Test: make magician-check-vcr-cassettes the only step Also collect passing and skipping tests collectResult no longer returns an error Remove extra return value gitignore magician binary Print logs Actually set logPaths and cassettePaths Rework management of environment variables Remove extra ] Also print all_tests.log Echo home Include HOME in env Echo path Use GOCACHE instead of HOME add -vet=off Run all tests, skip printing logs Run 24 tests and upload logs Add -r and remove logs Also upload cassettes Run tests for one resource in recording Run tests for one resource in replaying Also capture PATH Run recording again Clone hashicorp provider instead of mm Run all tests Run replaying Move check cassettes to push-downstream Remove echo PATH change to GA in doc (GoogleCloudPlatform#9491) Co-authored-by: Edward Sun <[email protected]> Refactor magician structs (GoogleCloudPlatform#9605) * Refactored github interfaces Fixed bug in overriding breaking changes * gofmt * Removed GetPullRequestLabelIDs Use magician for generate comment Fix formatting of breaking changes Keep diff string empty Add missing newline Add copyright notices Add missing space Revert changes from running generate-comment Run cassettes on main Print logs Rework management of environment variables change to GA in doc (GoogleCloudPlatform#9491) Co-authored-by: Edward Sun <[email protected]> git checkout main gcb-generate-diffs-new.yml
- Loading branch information
Showing
10 changed files
with
696 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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 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,104 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"magician/vcr" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// TODO(trodge): Move this into magician/github along with repo cloning | ||
const githubUsername = "modular-magician" | ||
|
||
var environmentVariables = [...]string{ | ||
"COMMIT_SHA", | ||
"GITHUB_TOKEN", | ||
"GOCACHE", | ||
"GOPATH", | ||
"GOOGLE_BILLING_ACCOUNT", | ||
"GOOGLE_CUST_ID", | ||
"GOOGLE_FIRESTORE_PROJECT", | ||
"GOOGLE_IDENTITY_USER", | ||
"GOOGLE_MASTER_BILLING_ACCOUNT", | ||
"GOOGLE_ORG", | ||
"GOOGLE_ORG_2", | ||
"GOOGLE_ORG_DOMAIN", | ||
"GOOGLE_PROJECT", | ||
"GOOGLE_PROJECT_NUMBER", | ||
"GOOGLE_REGION", | ||
"GOOGLE_SERVICE_ACCOUNT", | ||
"GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION", | ||
"GOOGLE_ZONE", | ||
"PATH", | ||
"SA_KEY", | ||
} | ||
|
||
var checkCassettesCmd = &cobra.Command{ | ||
Use: "check-cassettes", | ||
Short: "Run VCR tests on downstream main branch", | ||
Long: `This command runs after downstream changes are merged and runs the most recent | ||
VCR cassettes using the newly built beta provider. | ||
The following environment variables are expected: | ||
` + listEnvironmentVariables() + ` | ||
It prints a list of tests that failed in replaying mode along with all test output.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
env := make(map[string]string, len(environmentVariables)) | ||
for _, ev := range environmentVariables { | ||
val, ok := os.LookupEnv(ev) | ||
if !ok { | ||
fmt.Printf("Did not provide %s environment variable\n", ev) | ||
os.Exit(1) | ||
} | ||
env[ev] = val | ||
} | ||
|
||
t, err := vcr.NewTester(env) | ||
if err != nil { | ||
fmt.Println("Error creating VCR tester: ", err) | ||
os.Exit(1) | ||
} | ||
execCheckCassettes(t, env["GOPATH"], env["GITHUB_TOKEN"], env["COMMIT_SHA"]) | ||
}, | ||
} | ||
|
||
func listEnvironmentVariables() string { | ||
var result string | ||
for i, ev := range environmentVariables { | ||
result += fmt.Sprintf("\t%2d. %s\n", i+1, ev) | ||
} | ||
return result | ||
} | ||
|
||
func execCheckCassettes(t vcr.Tester, goPath, githubToken, commit string) { | ||
if err := t.FetchCassettes(vcr.Beta); err != nil { | ||
fmt.Println("Error fetching cassettes: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
if err := t.CloneProvider(goPath, githubUsername, githubToken, "downstream-pr-"+commit, vcr.Beta); err != nil { | ||
fmt.Println("Error cloning provider: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
result, err := t.Run(vcr.Replaying, vcr.Beta) | ||
if err != nil { | ||
fmt.Println("Error running VCR: ", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Failing tests: ", result.FailedTests) | ||
// TODO(trodge) report these failures to bigquery | ||
fmt.Println("Passing tests: ", result.PassedTests) | ||
fmt.Println("Skipping tests: ", result.SkippedTests) | ||
|
||
if err := t.Cleanup(); err != nil { | ||
fmt.Println("Error cleaning up vcr tester: ", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(checkCassettesCmd) | ||
} |
Oops, something went wrong.