1
1
import { expect } from "chai" ;
2
2
import * as sinon from "sinon" ;
3
3
import { Config } from "../../config" ;
4
- import { FirebaseError } from "../../error" ;
5
- import { AppHostingSingle } from "../../firebaseConfig" ;
6
4
import * as gcs from "../../gcp/storage" ;
7
5
import { RC } from "../../rc" ;
8
6
import { Context } from "./args" ;
@@ -26,24 +24,20 @@ const BASE_OPTS = {
26
24
27
25
function initializeContext ( ) : Context {
28
26
return {
29
- backendConfigs : new Map < string , AppHostingSingle > ( [
30
- [
31
- "foo" ,
32
- {
33
- backendId : "foo" ,
34
- rootDir : "/" ,
35
- ignore : [ ] ,
36
- } ,
37
- ] ,
38
- ] ) ,
39
- backendLocations : new Map < string , string > ( [ [ "foo" , "us-central1" ] ] ) ,
40
- backendStorageUris : new Map < string , string > ( ) ,
27
+ backendConfigs : {
28
+ foo : {
29
+ backendId : "foo" ,
30
+ rootDir : "/" ,
31
+ ignore : [ ] ,
32
+ } ,
33
+ } ,
34
+ backendLocations : { foo : "us-central1" } ,
35
+ backendStorageUris : { } ,
41
36
} ;
42
37
}
43
38
44
39
describe ( "apphosting" , ( ) => {
45
- let getBucketStub : sinon . SinonStub ;
46
- let createBucketStub : sinon . SinonStub ;
40
+ let upsertBucketStub : sinon . SinonStub ;
47
41
let uploadObjectStub : sinon . SinonStub ;
48
42
let createArchiveStub : sinon . SinonStub ;
49
43
let createReadStreamStub : sinon . SinonStub ;
@@ -53,8 +47,7 @@ describe("apphosting", () => {
53
47
getProjectNumberStub = sinon
54
48
. stub ( getProjectNumber , "getProjectNumber" )
55
49
. throws ( "Unexpected getProjectNumber call" ) ;
56
- getBucketStub = sinon . stub ( gcs , "getBucket" ) . throws ( "Unexpected getBucket call" ) ;
57
- createBucketStub = sinon . stub ( gcs , "createBucket" ) . throws ( "Unexpected createBucket call" ) ;
50
+ upsertBucketStub = sinon . stub ( gcs , "upsertBucket" ) . throws ( "Unexpected upsertBucket call" ) ;
58
51
uploadObjectStub = sinon . stub ( gcs , "uploadObject" ) . throws ( "Unexpected uploadObject call" ) ;
59
52
createArchiveStub = sinon . stub ( util , "createArchive" ) . throws ( "Unexpected createArchive call" ) ;
60
53
createReadStreamStub = sinon
@@ -80,15 +73,10 @@ describe("apphosting", () => {
80
73
} ) ,
81
74
} ;
82
75
83
- it ( "creates regional GCS bucket if one doesn't exist yet " , async ( ) => {
76
+ it ( "upserts regional GCS bucket" , async ( ) => {
84
77
const context = initializeContext ( ) ;
85
78
getProjectNumberStub . resolves ( "000000000000" ) ;
86
- getBucketStub . onFirstCall ( ) . rejects (
87
- new FirebaseError ( "error" , {
88
- original : new FirebaseError ( "original error" , { status : 404 } ) ,
89
- } ) ,
90
- ) ;
91
- createBucketStub . resolves ( ) ;
79
+ upsertBucketStub . resolves ( ) ;
92
80
createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
93
81
uploadObjectStub . resolves ( {
94
82
bucket : "firebaseapphosting-sources-12345678-us-central1" ,
@@ -98,14 +86,30 @@ describe("apphosting", () => {
98
86
99
87
await deploy ( context , opts ) ;
100
88
101
- expect ( createBucketStub ) . to . be . calledOnce ;
89
+ expect ( upsertBucketStub ) . to . be . calledWith ( {
90
+ product : "apphosting" ,
91
+ createMessage :
92
+ "Creating Cloud Storage bucket in us-central1 to store App Hosting source code uploads at firebaseapphosting-sources-000000000000-us-central1..." ,
93
+ projectId : "my-project" ,
94
+ req : {
95
+ name : "firebaseapphosting-sources-000000000000-us-central1" ,
96
+ location : "us-central1" ,
97
+ lifecycle : {
98
+ rule : [
99
+ {
100
+ action : { type : "Delete" } ,
101
+ condition : { age : 30 } ,
102
+ } ,
103
+ ] ,
104
+ } ,
105
+ } ,
106
+ } ) ;
102
107
} ) ;
103
108
104
109
it ( "correctly creates and sets storage URIs" , async ( ) => {
105
110
const context = initializeContext ( ) ;
106
111
getProjectNumberStub . resolves ( "000000000000" ) ;
107
- getBucketStub . resolves ( ) ;
108
- createBucketStub . resolves ( ) ;
112
+ upsertBucketStub . resolves ( ) ;
109
113
createArchiveStub . resolves ( "path/to/foo-1234.zip" ) ;
110
114
uploadObjectStub . resolves ( {
111
115
bucket : "firebaseapphosting-sources-12345678-us-central1" ,
@@ -115,7 +119,7 @@ describe("apphosting", () => {
115
119
116
120
await deploy ( context , opts ) ;
117
121
118
- expect ( context . backendStorageUris . get ( "foo" ) ) . to . equal (
122
+ expect ( context . backendStorageUris [ "foo" ] ) . to . equal (
119
123
"gs://firebaseapphosting-sources-000000000000-us-central1/foo-1234.zip" ,
120
124
) ;
121
125
} ) ;
0 commit comments