11import * as sinon from "sinon" ;
22import * as rollout from "../../apphosting/rollout" ;
3+ import * as backend from "../../apphosting/backend" ;
34import { Config } from "../../config" ;
45import { RC } from "../../rc" ;
6+ import { needProjectId } from "../../projectUtils" ;
57import { Context } from "./args" ;
68import release from "./release" ;
79import { expect } from "chai" ;
10+ import * as experiments from "../../experiments" ;
11+ import { isEnabled } from "../../experiments" ;
812
913const BASE_OPTS = {
1014 cwd : "/" ,
@@ -18,7 +22,14 @@ const BASE_OPTS = {
1822} ;
1923
2024describe ( "apphosting" , ( ) => {
25+ let isEnabledStub : sinon . SinonStub ;
2126 let orchestrateRolloutStub : sinon . SinonStub ;
27+ let getBackendStub : sinon . SinonStub ;
28+
29+ beforeEach ( ( ) => {
30+ isEnabledStub = sinon . stub ( experiments , "isEnabled" ) . returns ( false ) ;
31+ getBackendStub = sinon . stub ( backend , "getBackend" ) . resolves ( { uri : "https://foo-us-central1.a.run.app" } as any ) ;
32+ } ) ;
2233
2334 afterEach ( ( ) => {
2435 sinon . verifyAndRestore ( ) ;
@@ -63,5 +74,107 @@ describe("apphosting", () => {
6374
6475 await expect ( release ( context , opts ) ) . to . eventually . not . rejected ;
6576 } ) ;
77+
78+ it ( "uses archive for standard source deployments" , async ( ) => {
79+ const context : Context = {
80+ backendConfigs : {
81+ foo : {
82+ backendId : "foo" ,
83+ rootDir : "/" ,
84+ ignore : [ ] ,
85+ } ,
86+ } ,
87+ backendLocations : { foo : "us-central1" } ,
88+ backendStorageUris : {
89+ foo : "gs://bucket/source.zip" ,
90+ } ,
91+ backendLocalBuilds : { } ,
92+ } ;
93+
94+ orchestrateRolloutStub = sinon . stub ( rollout , "orchestrateRollout" ) . resolves ( ) ;
95+
96+ await release ( context , opts ) ;
97+
98+ expect ( orchestrateRolloutStub ) . to . be . calledOnceWith ( sinon . match ( {
99+ buildInput : {
100+ source : {
101+ archive : {
102+ userStorageUri : "gs://bucket/source.zip" ,
103+ rootDirectory : "/" ,
104+ } ,
105+ } ,
106+ } ,
107+ } ) ) ;
108+ } ) ;
109+
110+ it ( "uses locallyBuilt for local builds when experiment is enabled" , async ( ) => {
111+ isEnabledStub . withArgs ( "apphostinglocalbuilds" ) . returns ( true ) ;
112+ const context : Context = {
113+ backendConfigs : {
114+ foo : {
115+ backendId : "foo" ,
116+ rootDir : "/" ,
117+ ignore : [ ] ,
118+ localBuild : true ,
119+ } ,
120+ } ,
121+ backendLocations : { foo : "us-central1" } ,
122+ backendStorageUris : {
123+ foo : "gs://bucket/built.tar.gz" ,
124+ } ,
125+ backendLocalBuilds : {
126+ foo : {
127+ buildDir : "dist" ,
128+ buildConfig : { } ,
129+ annotations : { } ,
130+ } ,
131+ } ,
132+ } ;
133+
134+ orchestrateRolloutStub = sinon . stub ( rollout , "orchestrateRollout" ) . resolves ( ) ;
135+
136+ await release ( context , opts ) ;
137+
138+ expect ( orchestrateRolloutStub ) . to . be . calledOnceWith ( sinon . match ( {
139+ buildInput : {
140+ source : {
141+ locallyBuilt : {
142+ userStorageUri : "gs://bucket/built.tar.gz" ,
143+ } ,
144+ } ,
145+ } ,
146+ } ) ) ;
147+ } ) ;
148+
149+ it ( "skips local builds when experiment is disabled" , async ( ) => {
150+ isEnabledStub . withArgs ( "apphostinglocalbuilds" ) . returns ( false ) ;
151+ const context : Context = {
152+ backendConfigs : {
153+ foo : {
154+ backendId : "foo" ,
155+ rootDir : "/" ,
156+ ignore : [ ] ,
157+ localBuild : true ,
158+ } ,
159+ } ,
160+ backendLocations : { foo : "us-central1" } ,
161+ backendStorageUris : {
162+ foo : "gs://bucket/built.tar.gz" ,
163+ } ,
164+ backendLocalBuilds : {
165+ foo : {
166+ buildDir : "dist" ,
167+ buildConfig : { } ,
168+ annotations : { } ,
169+ } ,
170+ } ,
171+ } ;
172+
173+ orchestrateRolloutStub = sinon . stub ( rollout , "orchestrateRollout" ) . resolves ( ) ;
174+
175+ await release ( context , opts ) ;
176+
177+ expect ( orchestrateRolloutStub ) . to . not . be . called ;
178+ } ) ;
66179 } ) ;
67180} ) ;
0 commit comments