|
3 | 3 | require "spec_helper"
|
4 | 4 |
|
5 | 5 | describe Command::PromoteAppFromUpstream do
|
6 |
| - context "when release script is not provided" do |
7 |
| - let!(:token) { Shell.cmd("cpln", "profile", "token", "default")[:output].strip } |
8 |
| - let!(:upstream_app) { dummy_test_app } |
9 |
| - let!(:app) { dummy_test_app("nothing") } |
| 6 | + subject(:result) do |
| 7 | + run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token, *extra_args) |
| 8 | + end |
10 | 9 |
|
11 |
| - before do |
12 |
| - stub_env("CPLN_UPSTREAM", upstream_app) |
13 |
| - # Ideally, we should have a different org, but for testing purposes, this works |
14 |
| - stub_env("CPLN_ORG_UPSTREAM", dummy_test_org) |
| 10 | + let(:upstream_app) { dummy_test_app } |
| 11 | + let(:token) { Shell.cmd("cpln", "profile", "token", "default")[:output].strip } |
| 12 | + let(:extra_args) { [] } |
15 | 13 |
|
16 |
| - run_cpflow_command!("apply-template", "app", "-a", upstream_app) |
17 |
| - run_cpflow_command!("apply-template", "app", "rails", "-a", app) |
18 |
| - run_cpflow_command!("build-image", "-a", upstream_app) |
19 |
| - end |
| 14 | + before do |
| 15 | + stub_env("CPLN_UPSTREAM", upstream_app) |
| 16 | + # Ideally, we should have a different org, but for testing purposes, this works |
| 17 | + stub_env("CPLN_ORG_UPSTREAM", dummy_test_org) |
| 18 | + stub_env("APP_NAME", app) |
20 | 19 |
|
21 |
| - after do |
22 |
| - run_cpflow_command!("delete", "-a", upstream_app, "--yes") |
23 |
| - run_cpflow_command!("delete", "-a", app, "--yes") |
24 |
| - end |
| 20 | + run_cpflow_command!("apply-template", "app", "-a", upstream_app) |
| 21 | + run_cpflow_command!("apply-template", "app", "rails", "postgres", "-a", app) |
| 22 | + run_cpflow_command!("build-image", "-a", upstream_app) |
| 23 | + end |
25 | 24 |
|
26 |
| - it "copies latest image from upstream, skips release script and deploys image", :slow do |
27 |
| - result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) |
| 25 | + after do |
| 26 | + run_cpflow_command!("delete", "-a", upstream_app, "--yes") |
| 27 | + run_cpflow_command!("delete", "-a", app, "--yes") |
| 28 | + end |
28 | 29 |
|
| 30 | + shared_examples "copies latest image from upstream and deploys image" do |**options| |
| 31 | + it "#{options[:runs_release_script] ? 'runs' : 'does not run'} release script", :slow do |
29 | 32 | expect(result[:status]).to eq(0)
|
30 | 33 | expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
|
31 | 34 | expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'})
|
32 |
| - expect(result[:stderr]).not_to include("Running release script") |
33 |
| - expect(result[:stderr]).to match(/Deploying image '#{app}:1@sha256:[a-fA-F0-9]{64}'/) |
| 35 | + |
| 36 | + if options[:runs_release_script] |
| 37 | + expect(result[:stderr]).to include("Running release script") |
| 38 | + else |
| 39 | + expect(result[:stderr]).not_to include("Running release script") |
| 40 | + end |
| 41 | + |
| 42 | + if options[:uses_digest_image_ref] |
| 43 | + expect(result[:stderr]).to match(/Deploying image '#{app}:1@sha256:[a-fA-F0-9]{64}'/) |
| 44 | + else |
| 45 | + expect(result[:stderr]).to match(/Deploying image '#{app}:1(?!@)'/) |
| 46 | + end |
| 47 | + |
34 | 48 | expect(result[:stderr]).to match(%r{rails: https://rails-.+?.cpln.app})
|
35 | 49 | end
|
36 | 50 | end
|
37 | 51 |
|
| 52 | + context "when release script is not provided" do |
| 53 | + let(:app) { dummy_test_app("nothing") } |
| 54 | + |
| 55 | + it_behaves_like "copies latest image from upstream and deploys image", |
| 56 | + runs_release_script: false, |
| 57 | + uses_digest_image_ref: false |
| 58 | + |
| 59 | + context "with use_digest_image_ref from YAML file" do |
| 60 | + let(:app) { dummy_test_app("use-digest-image-ref") } |
| 61 | + |
| 62 | + it_behaves_like "copies latest image from upstream and deploys image", |
| 63 | + runs_release_script: false, |
| 64 | + uses_digest_image_ref: true |
| 65 | + end |
| 66 | + |
| 67 | + context "with --use-digest-image-ref option" do |
| 68 | + let(:extra_args) { ["--use-digest-image-ref"] } |
| 69 | + |
| 70 | + it_behaves_like "copies latest image from upstream and deploys image", |
| 71 | + runs_release_script: false, |
| 72 | + uses_digest_image_ref: true |
| 73 | + end |
| 74 | + end |
| 75 | + |
38 | 76 | context "when release script is invalid" do
|
39 |
| - let!(:token) { Shell.cmd("cpln", "profile", "token", "default")[:output].strip } |
40 |
| - let!(:upstream_app) { dummy_test_app } |
41 |
| - let!(:app) { dummy_test_app("invalid-release-script") } |
| 77 | + let(:app) { dummy_test_app("invalid-release-script") } |
42 | 78 |
|
43 | 79 | before do
|
44 |
| - stub_env("CPLN_UPSTREAM", upstream_app) |
45 |
| - # Ideally, we should have a different org, but for testing purposes, this works |
46 |
| - stub_env("CPLN_ORG_UPSTREAM", dummy_test_org) |
47 |
| - stub_env("APP_NAME", app) |
48 |
| - |
49 |
| - run_cpflow_command!("apply-template", "app", "-a", upstream_app) |
50 |
| - run_cpflow_command!("apply-template", "app", "rails", "postgres", "-a", app) |
51 |
| - run_cpflow_command!("build-image", "-a", upstream_app) |
52 | 80 | run_cpflow_command!("ps:start", "-a", app, "--workload", "postgres", "--wait")
|
53 | 81 | end
|
54 | 82 |
|
55 |
| - after do |
56 |
| - run_cpflow_command!("delete", "-a", upstream_app, "--yes") |
57 |
| - run_cpflow_command!("delete", "-a", app, "--yes") |
58 |
| - end |
59 |
| - |
60 | 83 | it "copies latest image from upstream, fails to run release script and fails to deploy image", :slow do
|
61 | 84 | result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token)
|
62 | 85 |
|
|
71 | 94 | end
|
72 | 95 |
|
73 | 96 | context "when release script is valid" do
|
74 |
| - let!(:token) { Shell.cmd("cpln", "profile", "token", "default")[:output].strip } |
75 |
| - let!(:upstream_app) { dummy_test_app } |
76 |
| - let!(:app) { dummy_test_app } |
| 97 | + let(:app) { dummy_test_app } |
77 | 98 |
|
78 | 99 | before do
|
79 |
| - stub_env("CPLN_UPSTREAM", upstream_app) |
80 |
| - # Ideally, we should have a different org, but for testing purposes, this works |
81 |
| - stub_env("CPLN_ORG_UPSTREAM", dummy_test_org) |
82 |
| - stub_env("APP_NAME", app) |
83 |
| - |
84 |
| - run_cpflow_command!("apply-template", "app", "-a", upstream_app) |
85 |
| - run_cpflow_command!("apply-template", "app", "rails", "postgres", "-a", app) |
86 |
| - run_cpflow_command!("build-image", "-a", upstream_app) |
87 | 100 | run_cpflow_command!("ps:start", "-a", app, "--workload", "postgres", "--wait")
|
88 | 101 | end
|
89 | 102 |
|
90 |
| - after do |
91 |
| - run_cpflow_command!("delete", "-a", upstream_app, "--yes") |
92 |
| - run_cpflow_command!("delete", "-a", app, "--yes") |
93 |
| - end |
94 |
| - |
95 |
| - it "copies latest image from upstream, runs release script and deploys image", :slow do |
96 |
| - result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) |
97 |
| - |
98 |
| - expect(result[:status]).to eq(0) |
99 |
| - expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'}) |
100 |
| - expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'}) |
101 |
| - expect(result[:stderr]).to include("Running release script") |
102 |
| - expect(result[:stderr]).to include("Finished running release script") |
103 |
| - expect(result[:stderr]).to match(/Deploying image '#{app}:1@sha256:[a-fA-F0-9]{64}'/) |
104 |
| - expect(result[:stderr]).to match(%r{rails: https://rails-.+?.cpln.app}) |
105 |
| - end |
| 103 | + it_behaves_like "copies latest image from upstream and deploys image", |
| 104 | + runs_release_script: true, |
| 105 | + uses_digest_image_ref: false |
106 | 106 | end
|
107 | 107 | end
|
0 commit comments