mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 19:28:33 +00:00
chore: Make e2e tests more vcs agnostic (#4836)
This commit is contained in:
20
e2e/e2e.go
20
e2e/e2e.go
@@ -128,7 +128,7 @@ func (t *E2ETester) Start(ctx context.Context) (*E2EResult, error) {
|
||||
// waiting for atlantis run and finish
|
||||
maxLoops := 20
|
||||
i := 0
|
||||
for ; i < maxLoops && checkStatus(state); i++ {
|
||||
for ; i < maxLoops && t.vcsClient.IsAtlantisInProgress(state); i++ {
|
||||
time.Sleep(2 * time.Second)
|
||||
state, _ = t.vcsClient.GetAtlantisStatus(ctx, branchName)
|
||||
if state == "" {
|
||||
@@ -144,22 +144,13 @@ func (t *E2ETester) Start(ctx context.Context) (*E2EResult, error) {
|
||||
log.Printf("atlantis run finished with status %q", state)
|
||||
e2eResult.testResult = state
|
||||
// check if atlantis run was a success
|
||||
if state != "success" {
|
||||
if !t.vcsClient.DidAtlantisSucceed(state) {
|
||||
return e2eResult, fmt.Errorf("atlantis run project type %q failed with %q status", t.projectType.Name, state)
|
||||
}
|
||||
|
||||
return e2eResult, nil
|
||||
}
|
||||
|
||||
func checkStatus(state string) bool {
|
||||
for _, s := range []string{"success", "error", "failure"} {
|
||||
if state == s {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func cleanUp(ctx context.Context, t *E2ETester, pullRequestNumber int, branchName string) error {
|
||||
// clean up
|
||||
err := t.vcsClient.ClosePullRequest(ctx, pullRequestNumber)
|
||||
@@ -168,12 +159,11 @@ func cleanUp(ctx context.Context, t *E2ETester, pullRequestNumber int, branchNam
|
||||
}
|
||||
log.Printf("closed pull request %d", pullRequestNumber)
|
||||
|
||||
deleteBranchName := fmt.Sprintf("%s/%s", "heads", branchName)
|
||||
err = t.vcsClient.DeleteBranch(ctx, deleteBranchName)
|
||||
err = t.vcsClient.DeleteBranch(ctx, branchName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while deleting branch %s: %v", deleteBranchName, err)
|
||||
return fmt.Errorf("error while deleting branch %s: %v", branchName, err)
|
||||
}
|
||||
log.Printf("deleted branch %s", deleteBranchName)
|
||||
log.Printf("deleted branch %s", branchName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -153,9 +153,23 @@ func (g GithubClient) ClosePullRequest(ctx context.Context, pullRequestNumber in
|
||||
}
|
||||
func (g GithubClient) DeleteBranch(ctx context.Context, branchName string) error {
|
||||
|
||||
_, err := g.client.Git.DeleteRef(ctx, g.ownerName, g.repoName, branchName)
|
||||
deleteBranchName := fmt.Sprintf("%s/%s", "heads", branchName)
|
||||
_, err := g.client.Git.DeleteRef(ctx, g.ownerName, g.repoName, deleteBranchName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while deleting branch %s: %v", branchName, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g GithubClient) IsAtlantisInProgress(state string) bool {
|
||||
for _, s := range []string{"success", "error", "failure"} {
|
||||
if state == s {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (g GithubClient) DidAtlantisSucceed(state string) bool {
|
||||
return state == "success"
|
||||
}
|
||||
|
||||
@@ -23,4 +23,6 @@ type VCSClient interface {
|
||||
GetAtlantisStatus(ctx context.Context, branchName string) (string, error)
|
||||
ClosePullRequest(ctx context.Context, pullRequestNumber int) error
|
||||
DeleteBranch(ctx context.Context, branchName string) error
|
||||
IsAtlantisInProgress(state string) bool
|
||||
DidAtlantisSucceed(state string) bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user