8
8
} from "../app/v3/getDeploymentImageRef.server" ;
9
9
import { DeleteRepositoryCommand } from "@aws-sdk/client-ecr" ;
10
10
11
- describe . skipIf ( process . env . RUN_REGISTRY_TESTS !== "1" ) ( "getDeploymentImageRef" , ( ) => {
11
+ describe ( "getDeploymentImageRef" , ( ) => {
12
12
const testHost =
13
13
process . env . DEPLOY_REGISTRY_HOST || "123456789012.dkr.ecr.us-east-1.amazonaws.com" ;
14
14
const testNamespace = process . env . DEPLOY_REGISTRY_NAMESPACE || "test-namespace" ;
@@ -25,7 +25,7 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
25
25
26
26
// Clean up test repository after tests
27
27
afterAll ( async ( ) => {
28
- if ( process . env . KEEP_TEST_REPO === "1" ) {
28
+ if ( process . env . KEEP_TEST_REPO === "1" || process . env . RUN_ECR_TESTS !== "1" ) {
29
29
return ;
30
30
}
31
31
@@ -57,7 +57,7 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
57
57
it ( "should return the correct image ref for non-ECR registry" , async ( ) => {
58
58
const imageRef = await getDeploymentImageRef ( {
59
59
registry : {
60
- host : "registry.digitalocean .com" ,
60
+ host : "registry.example .com" ,
61
61
namespace : testNamespace ,
62
62
username : "test-user" ,
63
63
password : "test-pass" ,
@@ -67,17 +67,69 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
67
67
} ,
68
68
projectRef : testProjectRef ,
69
69
nextVersion : "20250630.1" ,
70
- environmentSlug : "test" ,
70
+ environmentType : "DEVELOPMENT" ,
71
+ deploymentShortCode : "test1234" ,
71
72
} ) ;
72
73
74
+ // Check the image ref structure and that it contains expected parts
73
75
expect ( imageRef . imageRef ) . toBe (
74
- `registry.digitalocean .com/${ testNamespace } /${ testProjectRef } :20250630.1.test `
76
+ `registry.example .com/${ testNamespace } /${ testProjectRef } :20250630.1.development.test1234 `
75
77
) ;
76
78
expect ( imageRef . isEcr ) . toBe ( false ) ;
77
79
} ) ;
78
80
79
- it ( "should create ECR repository and return correct image ref" , async ( ) => {
80
- const imageRef1 = await getDeploymentImageRef ( {
81
+ it . skipIf ( process . env . RUN_ECR_TESTS !== "1" ) (
82
+ "should create ECR repository and return correct image ref" ,
83
+ async ( ) => {
84
+ const imageRef1 = await getDeploymentImageRef ( {
85
+ registry : {
86
+ host : testHost ,
87
+ namespace : testNamespace ,
88
+ username : "test-user" ,
89
+ password : "test-pass" ,
90
+ ecrTags : registryTags ,
91
+ ecrAssumeRoleArn : roleArn ,
92
+ ecrAssumeRoleExternalId : externalId ,
93
+ } ,
94
+ projectRef : testProjectRef2 ,
95
+ nextVersion : "20250630.1" ,
96
+ environmentType : "DEVELOPMENT" ,
97
+ deploymentShortCode : "test1234" ,
98
+ } ) ;
99
+
100
+ expect ( imageRef1 . imageRef ) . toBe (
101
+ `${ testHost } /${ testNamespace } /${ testProjectRef2 } :20250630.1.development.test1234`
102
+ ) ;
103
+ expect ( imageRef1 . isEcr ) . toBe ( true ) ;
104
+ expect ( imageRef1 . repoCreated ) . toBe ( true ) ;
105
+
106
+ const imageRef2 = await getDeploymentImageRef ( {
107
+ registry : {
108
+ host : testHost ,
109
+ namespace : testNamespace ,
110
+ username : "test-user" ,
111
+ password : "test-pass" ,
112
+ ecrTags : registryTags ,
113
+ ecrAssumeRoleArn : roleArn ,
114
+ ecrAssumeRoleExternalId : externalId ,
115
+ } ,
116
+ projectRef : testProjectRef2 ,
117
+ nextVersion : "20250630.2" ,
118
+ environmentType : "DEVELOPMENT" ,
119
+ deploymentShortCode : "test1234" ,
120
+ } ) ;
121
+
122
+ expect ( imageRef2 . imageRef ) . toBe (
123
+ `${ testHost } /${ testNamespace } /${ testProjectRef2 } :20250630.2.development.test1234`
124
+ ) ;
125
+ expect ( imageRef2 . isEcr ) . toBe ( true ) ;
126
+ expect ( imageRef2 . repoCreated ) . toBe ( false ) ;
127
+ }
128
+ ) ;
129
+
130
+ it . skipIf ( process . env . RUN_ECR_TESTS !== "1" ) ( "should reuse existing ECR repository" , async ( ) => {
131
+ // This should use the repository created in the previous test
132
+ const imageRef = await getDeploymentImageRef ( {
81
133
registry : {
82
134
host : testHost ,
83
135
namespace : testNamespace ,
@@ -87,44 +139,42 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
87
139
ecrAssumeRoleArn : roleArn ,
88
140
ecrAssumeRoleExternalId : externalId ,
89
141
} ,
90
- projectRef : testProjectRef2 ,
91
- nextVersion : "20250630.1" ,
92
- environmentSlug : "test" ,
142
+ projectRef : testProjectRef ,
143
+ nextVersion : "20250630.2" ,
144
+ environmentType : "PRODUCTION" ,
145
+ deploymentShortCode : "test1234" ,
93
146
} ) ;
94
147
95
- expect ( imageRef1 . imageRef ) . toBe (
96
- `${ testHost } /${ testNamespace } /${ testProjectRef2 } :20250630.1.test `
148
+ expect ( imageRef . imageRef ) . toBe (
149
+ `${ testHost } /${ testNamespace } /${ testProjectRef } :20250630.2.production.test1234 `
97
150
) ;
98
- expect ( imageRef1 . isEcr ) . toBe ( true ) ;
99
- expect ( imageRef1 . repoCreated ) . toBe ( true ) ;
151
+ expect ( imageRef . isEcr ) . toBe ( true ) ;
152
+ } ) ;
153
+
154
+ it ( "should generate unique image tags for different deployments with same environment type" , async ( ) => {
155
+ // Simulates the scenario where multiple deployments happen to the same environment type
156
+ const sameEnvironmentType = "PREVIEW" ;
157
+ const sameVersion = "20250630.1" ;
100
158
101
- const imageRef2 = await getDeploymentImageRef ( {
159
+ const firstImageRef = await getDeploymentImageRef ( {
102
160
registry : {
103
- host : testHost ,
161
+ host : "registry.example.com" ,
104
162
namespace : testNamespace ,
105
163
username : "test-user" ,
106
164
password : "test-pass" ,
107
165
ecrTags : registryTags ,
108
166
ecrAssumeRoleArn : roleArn ,
109
167
ecrAssumeRoleExternalId : externalId ,
110
168
} ,
111
- projectRef : testProjectRef2 ,
112
- nextVersion : "20250630.2" ,
113
- environmentSlug : "test" ,
169
+ projectRef : testProjectRef ,
170
+ nextVersion : sameVersion ,
171
+ environmentType : sameEnvironmentType ,
172
+ deploymentShortCode : "test1234" ,
114
173
} ) ;
115
174
116
- expect ( imageRef2 . imageRef ) . toBe (
117
- `${ testHost } /${ testNamespace } /${ testProjectRef2 } :20250630.2.test`
118
- ) ;
119
- expect ( imageRef2 . isEcr ) . toBe ( true ) ;
120
- expect ( imageRef2 . repoCreated ) . toBe ( false ) ;
121
- } ) ;
122
-
123
- it ( "should reuse existing ECR repository" , async ( ) => {
124
- // This should use the repository created in the previous test
125
- const imageRef = await getDeploymentImageRef ( {
175
+ const secondImageRef = await getDeploymentImageRef ( {
126
176
registry : {
127
- host : testHost ,
177
+ host : "registry.example.com" ,
128
178
namespace : testNamespace ,
129
179
username : "test-user" ,
130
180
password : "test-pass" ,
@@ -133,37 +183,23 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
133
183
ecrAssumeRoleExternalId : externalId ,
134
184
} ,
135
185
projectRef : testProjectRef ,
136
- nextVersion : "20250630.2" ,
137
- environmentSlug : "prod" ,
186
+ nextVersion : sameVersion ,
187
+ environmentType : sameEnvironmentType ,
188
+ deploymentShortCode : "test4321" ,
138
189
} ) ;
139
190
140
- expect ( imageRef . imageRef ) . toBe (
141
- `${ testHost } /${ testNamespace } /${ testProjectRef } :20250630.2.prod`
191
+ // Even with the same environment type and version, the image refs should be different due to deployment short codes
192
+ expect ( firstImageRef . imageRef ) . toBe (
193
+ `registry.example.com/${ testNamespace } /${ testProjectRef } :${ sameVersion } .preview.test1234`
142
194
) ;
143
- expect ( imageRef . isEcr ) . toBe ( true ) ;
144
- } ) ;
145
-
146
- it ( "should throw error for invalid ECR host" , async ( ) => {
147
- await expect (
148
- getDeploymentImageRef ( {
149
- registry : {
150
- host : "invalid.ecr.amazonaws.com" ,
151
- namespace : testNamespace ,
152
- username : "test-user" ,
153
- password : "test-pass" ,
154
- ecrTags : registryTags ,
155
- ecrAssumeRoleArn : roleArn ,
156
- ecrAssumeRoleExternalId : externalId ,
157
- } ,
158
- projectRef : testProjectRef ,
159
- nextVersion : "20250630.1" ,
160
- environmentSlug : "test" ,
161
- } )
162
- ) . rejects . toThrow ( "Invalid ECR registry host: invalid.ecr.amazonaws.com" ) ;
195
+ expect ( secondImageRef . imageRef ) . toBe (
196
+ `registry.example.com/${ testNamespace } /${ testProjectRef } :${ sameVersion } .preview.test4321`
197
+ ) ;
198
+ expect ( firstImageRef . imageRef ) . not . toBe ( secondImageRef . imageRef ) ;
163
199
} ) ;
164
200
} ) ;
165
201
166
- describe . skipIf ( process . env . RUN_REGISTRY_AUTH_TESTS !== "1" ) ( "getEcrAuthToken" , ( ) => {
202
+ describe . skipIf ( process . env . RUN_ECR_TESTS !== "1" ) ( "getEcrAuthToken" , ( ) => {
167
203
const testHost =
168
204
process . env . DEPLOY_REGISTRY_HOST || "123456789012.dkr.ecr.us-east-1.amazonaws.com" ;
169
205
@@ -188,8 +224,7 @@ describe.skipIf(process.env.RUN_REGISTRY_AUTH_TESTS !== "1")("getEcrAuthToken",
188
224
expect ( auth . password . length ) . toBeGreaterThan ( 0 ) ;
189
225
190
226
// Verify the token format (should be a base64-encoded string)
191
- const base64Regex = / ^ [ A - Z a - z 0 - 9 + / = ] + $ / ;
192
- expect ( base64Regex . test ( auth . password ) ) . toBe ( true ) ;
227
+ expect ( auth . password ) . toMatch ( / ^ [ A - Z a - z 0 - 9 + / = ] + $ / ) ;
193
228
} ) ;
194
229
195
230
it ( "should throw error for invalid region" , async ( ) => {
0 commit comments