Skip to content

Commit 670ef52

Browse files
authored
test(e2e): add pipeline show and status cmds to e2e test (#2430)
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 59f8c87 commit 670ef52

File tree

5 files changed

+175
-4
lines changed

5 files changed

+175
-4
lines changed

.release/buildspec_e2e.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ batch:
118118
variables:
119119
TEST_SUITE: pipeline
120120
APP_REGION: eu-west-1
121+
TESTENV_REGION: eu-west-1
122+
PRODENV_REGION: eu-central-1
121123

122124

123125
phases:
@@ -134,7 +136,17 @@ phases:
134136
- export GOPATH=/go
135137
- rm -rf cf-custom-resources/node_modules
136138
- mkdir -p /tmp/.aws
137-
- printf "[default]\nregion = $APP_REGION\n[profile e2etestenv]\nregion=us-west-1\n[profile e2eprodenv]\nregion=us-east-1\n" > /tmp/.aws/config
139+
- TEST_RGN=$TESTENV_REGION
140+
- |
141+
if [ -z "$TEST_RGN" ]; then
142+
TEST_RGN=us-west-1
143+
fi
144+
- PROD_RGN=$PRODENV_REGION
145+
- |
146+
if [ -z "$PROD_RGN" ]; then
147+
PROD_RGN=us-east-1
148+
fi
149+
- printf "[default]\nregion = $APP_REGION\n[profile e2etestenv]\nregion=$TEST_RGN\n[profile e2eprodenv]\nregion=$PROD_RGN\n" > /tmp/.aws/config
138150
- printf "[default]\naws_access_key_id=$E2E_USER_1_ACCESS_KEY\naws_secret_access_key=$E2E_USER_1_SECRET_KEY\n\n[e2etestenv]\naws_access_key_id=$E2E_USER_2_ACCESS_KEY\naws_secret_access_key=$E2E_USER_2_SECRET_KEY\n\n[e2eprodenv]\naws_access_key_id=$E2E_USER_3_ACCESS_KEY\naws_secret_access_key=$E2E_USER_3_SECRET_KEY\n" > /tmp/.aws/credentials
139151
- sed -i -e '$s/$/ --noColor/' e2e/e2e.sh
140152
- make build-e2e

e2e/internal/client/cli.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package client
55

66
import (
7+
"encoding/json"
78
"fmt"
89
"os"
910
"os/exec"
@@ -632,6 +633,44 @@ func (cli *CLI) AppShow(appName string) (*AppShowOutput, error) {
632633
return toAppShowOutput(output)
633634
}
634635

636+
// PipelineInit runs "copilot pipeline init".
637+
func (cli *CLI) PipelineInit(app, url, branch string, envs []string) (string, error) {
638+
return cli.exec(
639+
exec.Command(cli.path, "pipeline", "init",
640+
"-a", app,
641+
"-u", url,
642+
"-b", branch,
643+
"-e", strings.Join(envs, ",")))
644+
}
645+
646+
// PipelineShow runs "copilot pipeline show --json"
647+
func (cli *CLI) PipelineShow() (*PipelineShowOutput, error) {
648+
text, err := cli.exec(
649+
exec.Command(cli.path, "pipeline", "show", "--json"))
650+
if err != nil {
651+
return nil, err
652+
}
653+
var out PipelineShowOutput
654+
if err := json.Unmarshal([]byte(text), &out); err != nil {
655+
return nil, err
656+
}
657+
return &out, nil
658+
}
659+
660+
// PipelineStatus runs "copilot pipeline status --json"
661+
func (cli *CLI) PipelineStatus() (*PipelineStatusOutput, error) {
662+
text, err := cli.exec(
663+
exec.Command(cli.path, "pipeline", "status", "--json"))
664+
if err != nil {
665+
return nil, err
666+
}
667+
var out PipelineStatusOutput
668+
if err := json.Unmarshal([]byte(text), &out); err != nil {
669+
return nil, err
670+
}
671+
return &out, nil
672+
}
673+
635674
/*AppList runs:
636675
copilot app ls
637676
*/

e2e/internal/client/outputs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,23 @@ func toEnvListOutput(jsonInput string) (*EnvListOutput, error) {
208208
var output EnvListOutput
209209
return &output, json.Unmarshal([]byte(jsonInput), &output)
210210
}
211+
212+
// PipelineShowOutput represents the JSON output of the "pipeline show" command.
213+
type PipelineShowOutput struct {
214+
Name string `json:"name"`
215+
Stages []struct {
216+
Name string `json:"name"`
217+
Category string `json:"category"`
218+
} `json:"stages"`
219+
}
220+
221+
// PipelineStatusOutput represents the JSON output of the "pipeline status" command.
222+
type PipelineStatusOutput struct {
223+
States struct {
224+
Name string `json:"stageName"`
225+
Actions []struct {
226+
Name string `json:"name"`
227+
Status string `json:"status"`
228+
} `json:"actions"`
229+
} `json:"stageStates"`
230+
}

e2e/pipeline/pipeline_suite_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
// CodeCommit credentials.
2929
var (
3030
repoName = appName
31+
repoURL string
3132
codeCommitIAMUser = fmt.Sprintf("%s-cc", appName)
3233
codeCommitCreds *client.IAMServiceCreds
3334
)
@@ -49,6 +50,8 @@ var _ = BeforeSuite(func() {
4950
})
5051

5152
var _ = AfterSuite(func() {
53+
_, err := copilot.AppDelete()
54+
Expect(err).NotTo(HaveOccurred())
5255
_ = aws.DeleteCodeCommitRepo(appName)
5356
_ = aws.DeleteCodeCommitIAMUser(codeCommitIAMUser, codeCommitCreds.CredentialID)
5457
})

e2e/pipeline/pipeline_test.go

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ import (
88
"net/url"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"strings"
1213

14+
"github.com/aws/copilot-cli/e2e/internal/client"
15+
1316
. "github.com/onsi/ginkgo"
1417
. "github.com/onsi/gomega"
1518
)
1619

1720
var _ = Describe("pipeline flow", func() {
1821
Context("setup CodeCommit repository", func() {
19-
var cloneURL string
2022
It("creates the codecommit repository", func() {
2123
url, err := aws.CreateCodeCommitRepo(repoName)
2224
Expect(err).NotTo(HaveOccurred())
23-
cloneURL = url
25+
repoURL = url
2426
})
2527

2628
It("clones the repository", func() {
27-
endpoint := strings.TrimPrefix(cloneURL, "https://")
29+
endpoint := strings.TrimPrefix(repoURL, "https://")
2830
url := fmt.Sprintf("https://%s:%s@%s", url.PathEscape(codeCommitCreds.UserName), url.PathEscape(codeCommitCreds.Password), endpoint)
2931

3032
Eventually(func() error {
@@ -44,16 +46,111 @@ var _ = Describe("pipeline flow", func() {
4446

4547
It("should push upstream", func() {
4648
cmd := exec.Command("git", "add", ".")
49+
cmd.Stdout = os.Stdout
50+
cmd.Stderr = os.Stderr
4751
cmd.Dir = repoName
4852
Expect(cmd.Run()).NotTo(HaveOccurred())
4953

5054
cmd = exec.Command("git", "commit", "-m", "first commit")
55+
cmd.Stdout = os.Stdout
56+
cmd.Stderr = os.Stderr
5157
cmd.Dir = repoName
5258
Expect(cmd.Run()).NotTo(HaveOccurred())
5359

5460
cmd = exec.Command("git", "push")
61+
cmd.Stdout = os.Stdout
62+
cmd.Stderr = os.Stderr
5563
cmd.Dir = repoName
5664
Expect(cmd.Run()).NotTo(HaveOccurred())
5765
})
5866
})
67+
68+
Context("create a new app", func() {
69+
It("app init succeeds", func() {
70+
_, err := copilot.AppInit(&client.AppInitRequest{
71+
AppName: appName,
72+
})
73+
Expect(err).NotTo(HaveOccurred())
74+
})
75+
It("app init creates an copilot directory and workspace file", func() {
76+
Expect(filepath.Join(repoName, "copilot")).Should(BeADirectory())
77+
Expect(filepath.Join(repoName, "copilot", ".workspace")).Should(BeAnExistingFile())
78+
})
79+
It("app ls includes new app", func() {
80+
Eventually(copilot.AppList, "30s", "5s").Should(ContainSubstring(appName))
81+
})
82+
It("app show includes app name", func() {
83+
appShowOutput, err := copilot.AppShow(appName)
84+
Expect(err).NotTo(HaveOccurred())
85+
Expect(appShowOutput.Name).To(Equal(appName))
86+
Expect(appShowOutput.URI).To(BeEmpty())
87+
})
88+
})
89+
90+
Context("when creating a new environment", func() {
91+
It("test env init should succeed", func() {
92+
_, err := copilot.EnvInit(&client.EnvInitRequest{
93+
AppName: appName,
94+
EnvName: "test",
95+
Profile: "e2etestenv",
96+
Prod: false,
97+
})
98+
Expect(err).NotTo(HaveOccurred())
99+
})
100+
It("prod env init should succeed", func() {
101+
_, err := copilot.EnvInit(&client.EnvInitRequest{
102+
AppName: appName,
103+
EnvName: "prod",
104+
Profile: "e2eprodenv",
105+
Prod: false,
106+
})
107+
Expect(err).NotTo(HaveOccurred())
108+
})
109+
It("env ls should list both envs", func() {
110+
out, err := copilot.EnvList(appName)
111+
Expect(err).NotTo(HaveOccurred())
112+
Expect(len(out.Envs)).To(Equal(2))
113+
envs := map[string]client.EnvDescription{}
114+
for _, env := range out.Envs {
115+
envs[env.Name] = env
116+
Expect(env.ExecutionRole).NotTo(BeEmpty())
117+
Expect(env.ManagerRole).NotTo(BeEmpty())
118+
}
119+
120+
Expect(envs["test"]).NotTo(BeNil())
121+
Expect(envs["prod"]).NotTo(BeNil())
122+
})
123+
})
124+
125+
Context("when creating the frontend service", func() {
126+
It("should initialize the service", func() {
127+
_, err := copilot.SvcInit(&client.SvcInitRequest{
128+
Name: "frontend",
129+
SvcType: "Load Balanced Web Service",
130+
Dockerfile: "./frontend/Dockerfile",
131+
SvcPort: "80",
132+
})
133+
Expect(err).NotTo(HaveOccurred())
134+
})
135+
It("should generate a manifest file", func() {
136+
Expect(filepath.Join(repoName, "copilot", "frontend", "manifest.yml")).Should(BeAnExistingFile())
137+
})
138+
It("should list the service", func() {
139+
out, err := copilot.SvcList(appName)
140+
Expect(err).NotTo(HaveOccurred())
141+
Expect(len(out.Services)).To(Equal(1))
142+
Expect(out.Services[0].Name).To(Equal("frontend"))
143+
})
144+
})
145+
146+
Context("when creating the pipeline manifest", func() {
147+
It("should initialize the pipeline", func() {
148+
_, err := copilot.PipelineInit(appName, repoURL, "master", []string{"test", "prod"})
149+
Expect(err).NotTo(HaveOccurred())
150+
})
151+
It("should generate pipeline artifacts", func() {
152+
Expect(filepath.Join(repoName, "copilot", "pipeline.yml")).Should(BeAnExistingFile())
153+
Expect(filepath.Join(repoName, "copilot", "buildspec.yml")).Should(BeAnExistingFile())
154+
})
155+
})
59156
})

0 commit comments

Comments
 (0)