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.
Magician check cassettes new (GoogleCloudPlatform#9630)
* Run cassettes on main 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 * Move Version into provider package and Repo into source package * Remove second walk func * Add , * Delete unused variable * Rename bucket * Include numbers of failed, passed, and skipped tests * Wait for vcr merge instead of tpgb push
- Loading branch information
Showing
3 changed files
with
452 additions
and
0 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,118 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"magician/exec" | ||
"magician/provider" | ||
"magician/source" | ||
"magician/vcr" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
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 | ||
} | ||
|
||
rnr, err := exec.NewRunner() | ||
if err != nil { | ||
fmt.Println("Error creating Runner: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
ctlr := source.NewController(env["GOPATH"], "modular-magician", env["GITHUB_TOKEN"], rnr) | ||
|
||
t, err := vcr.NewTester(env, rnr) | ||
if err != nil { | ||
fmt.Println("Error creating VCR tester: ", err) | ||
os.Exit(1) | ||
} | ||
execCheckCassettes(env["COMMIT_SHA"], t, ctlr) | ||
}, | ||
} | ||
|
||
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(commit string, t vcr.Tester, ctlr *source.Controller) { | ||
if err := t.FetchCassettes(provider.Beta); err != nil { | ||
fmt.Println("Error fetching cassettes: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
providerRepo := &source.Repo{ | ||
Name: provider.Beta.RepoName(), | ||
Branch: "downstream-pr-" + commit, | ||
} | ||
ctlr.SetPath(providerRepo) | ||
if err := ctlr.Clone(providerRepo); err != nil { | ||
fmt.Println("Error cloning provider: ", err) | ||
os.Exit(1) | ||
} | ||
t.SetRepoPath(provider.Beta, providerRepo.Path) | ||
|
||
result, err := t.Run(vcr.Replaying, provider.Beta) | ||
if err != nil { | ||
fmt.Println("Error running VCR: ", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println(len(result.FailedTests), " failed tests: ", result.FailedTests) | ||
// TODO(trodge) report these failures to bigquery | ||
fmt.Println(len(result.PassedTests), " passed tests: ", result.PassedTests) | ||
fmt.Println(len(result.SkippedTests), " skipped 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.