@@ -40,26 +40,32 @@ import { Artifact } from './artifact';
40
40
const log = new ToolingLog ( ) ;
41
41
let MOCKS ;
42
42
43
+ const DAILY_SNAPSHOT_BASE_URL = 'https://artifacts.opensearch.org/snapshots/core/opensearch' ;
44
+
45
+ const ORIGINAL_PLATFROM = process . platform ;
46
+ const ORIGINAL_ARCHITECTURE = process . arch ;
43
47
const PLATFORM = process . platform === 'win32' ? 'windows' : process . platform ;
44
48
const ARCHITECTURE = process . arch === 'arm64' ? 'arm64' : 'x64' ;
45
49
const MOCK_VERSION = 'test-version' ;
46
- const MOCK_URL = 'http://127.0.0.1:12345' ;
47
- const MOCK_FILENAME = 'test-filename' ;
50
+ const MOCK_RC_VERSION = `test-version-rc4` ;
51
+ const MOCK_FILENAME = 'opensearch-test-version-SNAPSHOT-linux-x64-latest.tar.gz' ;
52
+ const MOCK_RC_FILENAME = `opensearch-test-version-rc4-SNAPSHOT-linux-x64-latest.tar.gz` ;
53
+ const MOCK_URL = `${ DAILY_SNAPSHOT_BASE_URL } /${ MOCK_VERSION } /${ MOCK_FILENAME } ` ;
54
+ const MOCK_RC_URL = `${ DAILY_SNAPSHOT_BASE_URL } /${ MOCK_RC_VERSION } /${ MOCK_RC_FILENAME } ` ;
48
55
49
- const DAILY_SNAPSHOT_BASE_URL = '' ;
50
- const PERMANENT_SNAPSHOT_BASE_URL = '' ;
56
+ const itif = process . platform === 'linux' && process . arch === 'x64' ? it : it . skip ;
51
57
52
58
const createArchive = ( params = { } ) => {
53
- const license = params . license || 'default' ;
54
59
const architecture = params . architecture || ARCHITECTURE ;
60
+ const useRCVersion = params . useRCVersion || false ;
55
61
56
62
return {
57
- license : 'default ' ,
63
+ license : 'oss ' ,
58
64
architecture,
59
- version : MOCK_VERSION ,
60
- url : MOCK_URL + `/ ${ license } ` ,
65
+ version : ! useRCVersion ? MOCK_VERSION : MOCK_RC_VERSION ,
66
+ url : ! useRCVersion ? MOCK_URL : MOCK_RC_URL ,
61
67
platform : PLATFORM ,
62
- filename : MOCK_FILENAME + `- ${ architecture } . ${ license } ` ,
68
+ filename : ! useRCVersion ? MOCK_FILENAME : MOCK_RC_FILENAME ,
63
69
...params ,
64
70
} ;
65
71
} ;
@@ -92,99 +98,87 @@ beforeEach(() => {
92
98
jest . resetAllMocks ( ) ;
93
99
94
100
MOCKS = {
95
- valid : {
96
- archives : [ createArchive ( { license : 'oss' } ) , createArchive ( { license : 'default' } ) ] ,
101
+ GA : {
102
+ archives : [ createArchive ( { useRCVersion : false } ) ] ,
103
+ } ,
104
+ RC : {
105
+ archives : [ createArchive ( { useRCVersion : true } ) ] ,
97
106
} ,
98
107
multipleArch : {
99
108
archives : [
100
- createArchive ( { architecture : 'fake_arch' , license : 'oss' } ) ,
101
- createArchive ( { architecture : ARCHITECTURE , license : 'oss' } ) ,
109
+ createArchive ( { architecture : 'fake_arch' , useRCVersion : false } ) ,
110
+ createArchive ( { architecture : ARCHITECTURE , useRCVersion : false } ) ,
102
111
] ,
103
112
} ,
104
113
} ;
105
114
} ) ;
106
115
107
- const artifactTest = ( requestedLicense , expectedLicense , fetchTimesCalled = 1 ) => {
116
+ const artifactTest = ( fetchTimesCalled = 1 ) => {
108
117
return async ( ) => {
109
- const artifact = await Artifact . getSnapshot ( requestedLicense , MOCK_VERSION , log ) ;
118
+ const artifact = await Artifact . getSnapshot ( 'oss' , MOCK_VERSION , log ) ;
119
+ const expectedUrl = fetchTimesCalled === 1 ? MOCK_URL : MOCK_RC_URL ;
120
+ const expectedFilename = fetchTimesCalled === 1 ? MOCK_FILENAME : MOCK_RC_FILENAME ;
110
121
expect ( fetch ) . toHaveBeenCalledTimes ( fetchTimesCalled ) ;
111
- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual (
112
- `${ DAILY_SNAPSHOT_BASE_URL } /${ MOCK_VERSION } /manifest-latest-verified.json`
113
- ) ;
114
- if ( fetchTimesCalled === 2 ) {
115
- expect ( fetch . mock . calls [ 1 ] [ 0 ] ) . toEqual (
116
- `${ PERMANENT_SNAPSHOT_BASE_URL } /${ MOCK_VERSION } /manifest.json`
117
- ) ;
122
+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( MOCK_URL ) ;
123
+ if ( fetchTimesCalled !== 1 ) {
124
+ expect ( fetch . mock . calls [ fetchTimesCalled - 1 ] [ 0 ] ) . toEqual ( MOCK_RC_URL ) ;
118
125
}
119
- expect ( artifact . getUrl ( ) ) . toEqual ( MOCK_URL + `/ ${ expectedLicense } ` ) ;
120
- expect ( artifact . getChecksumUrl ( ) ) . toEqual ( MOCK_URL + `/ ${ expectedLicense } .sha512` ) ;
126
+ expect ( artifact . getUrl ( ) ) . toEqual ( expectedUrl ) ;
127
+ expect ( artifact . getChecksumUrl ( ) ) . toEqual ( expectedUrl + ' .sha512' ) ;
121
128
expect ( artifact . getChecksumType ( ) ) . toEqual ( 'sha512' ) ;
122
- expect ( artifact . getFilename ( ) ) . toEqual ( MOCK_FILENAME + `- ${ ARCHITECTURE } . ${ expectedLicense } ` ) ;
129
+ expect ( artifact . getFilename ( ) ) . toEqual ( expectedFilename ) ;
123
130
} ;
124
131
} ;
125
132
126
133
describe ( 'Artifact' , ( ) => {
127
134
describe ( 'getSnapshot()' , ( ) => {
128
- describe ( 'with default snapshot' , ( ) => {
129
- beforeEach ( ( ) => {
130
- mockFetch ( MOCKS . valid ) ;
131
- } ) ;
132
-
133
- it ( 'should return artifact metadata for a daily oss artifact' , artifactTest ( 'oss' , 'oss' ) ) ;
135
+ itif ( 'should return artifact metadata for a daily GA artifact' , ( ) => {
136
+ mockFetch ( MOCKS . GA ) ;
137
+ artifactTest ( ) ;
138
+ } ) ;
134
139
135
- it (
136
- 'should return artifact metadata for a daily default artifact' ,
137
- artifactTest ( 'default' , 'default' )
138
- ) ;
140
+ itif ( 'should return artifact metadata for a RC artifact' , ( ) => {
141
+ fetch . mockReturnValueOnce ( Promise . resolve ( new Response ( '' , { status : 404 } ) ) ) ;
142
+ fetch . mockReturnValueOnce ( Promise . resolve ( new Response ( '' , { status : 404 } ) ) ) ;
143
+ mockFetch ( MOCKS . RC ) ;
144
+ artifactTest ( 3 ) ;
145
+ } ) ;
139
146
140
- it (
141
- 'should default to default license with anything other than "oss"' ,
142
- artifactTest ( 'INVALID_LICENSE' , 'default' )
147
+ itif ( 'should throw when an artifact cannot be found for the specified parameters' , async ( ) => {
148
+ fetch . mockReturnValue ( Promise . resolve ( new Response ( '' , { status : 404 } ) ) ) ;
149
+ await expect ( Artifact . getSnapshot ( 'default' , 'INVALID_VERSION' , log ) ) . rejects . toThrow (
150
+ 'Snapshots for INVALID_VERSION are not available'
143
151
) ;
144
-
145
- it ( 'should throw when an artifact cannot be found in the manifest for the specified parameters' , async ( ) => {
146
- await expect ( Artifact . getSnapshot ( 'default' , 'INVALID_VERSION' , log ) ) . rejects . toThrow (
147
- "couldn't find an artifact"
148
- ) ;
149
- } ) ;
150
152
} ) ;
151
153
152
- describe ( 'with missing default snapshot' , ( ) => {
153
- beforeEach ( ( ) => {
154
- fetch . mockReturnValueOnce ( Promise . resolve ( new Response ( '' , { status : 404 } ) ) ) ;
155
- mockFetch ( MOCKS . valid ) ;
154
+ describe ( 'with snapshots for multiple architectures' , ( ) => {
155
+ afterAll ( ( ) => {
156
+ Object . defineProperties ( process , {
157
+ platform : {
158
+ value : ORIGINAL_PLATFROM ,
159
+ } ,
160
+ arch : {
161
+ value : ORIGINAL_ARCHITECTURE ,
162
+ } ,
163
+ } ) ;
156
164
} ) ;
157
165
158
- it (
159
- 'should return artifact metadata for a permanent oss artifact' ,
160
- artifactTest ( 'oss' , 'oss' , 2 )
161
- ) ;
162
-
163
- it (
164
- 'should return artifact metadata for a permanent default artifact' ,
165
- artifactTest ( 'default' , 'default' , 2 )
166
- ) ;
167
-
168
- it (
169
- 'should default to default license with anything other than "oss"' ,
170
- artifactTest ( 'INVALID_LICENSE' , 'default' , 2 )
171
- ) ;
172
-
173
- it ( 'should throw when an artifact cannot be found in the manifest for the specified parameters' , async ( ) => {
174
- await expect ( Artifact . getSnapshot ( 'default' , 'INVALID_VERSION' , log ) ) . rejects . toThrow (
175
- "couldn't find an artifact"
166
+ it ( 'should throw when on a non-Linux platform' , async ( ) => {
167
+ Object . defineProperty ( process , 'platform' , {
168
+ value : 'win32' ,
169
+ } ) ;
170
+ await expect ( Artifact . getSnapshot ( 'default' , 'INVALID_PLATFORM' , log ) ) . rejects . toThrow (
171
+ 'Snapshots are only available for Linux x64'
176
172
) ;
177
173
} ) ;
178
- } ) ;
179
174
180
- describe ( 'with snapshots for multiple architectures' , ( ) => {
181
- beforeEach ( ( ) => {
182
- mockFetch ( MOCKS . multipleArch ) ;
183
- } ) ;
184
-
185
- it ( 'should return artifact metadata for the correct architecture' , async ( ) => {
186
- const artifact = await Artifact . getSnapshot ( 'oss' , MOCK_VERSION , log ) ;
187
- expect ( artifact . getFilename ( ) ) . toEqual ( MOCK_FILENAME + `-${ ARCHITECTURE } .oss` ) ;
175
+ it ( 'should throw when on a non-x64 arch' , async ( ) => {
176
+ Object . defineProperty ( process , 'arch' , {
177
+ value : 'arm64' ,
178
+ } ) ;
179
+ await expect ( Artifact . getSnapshot ( 'default' , 'INVALID_ARCH' , log ) ) . rejects . toThrow (
180
+ 'Snapshots are only available for Linux x64'
181
+ ) ;
188
182
} ) ;
189
183
} ) ;
190
184
@@ -193,7 +187,7 @@ describe('Artifact', () => {
193
187
194
188
beforeEach ( ( ) => {
195
189
process . env . OPENSEARCH_SNAPSHOT_MANIFEST = CUSTOM_URL ;
196
- mockFetch ( MOCKS . valid ) ;
190
+ mockFetch ( MOCKS . GA ) ;
197
191
} ) ;
198
192
199
193
it ( 'should use the custom URL when looking for a snapshot' , async ( ) => {
@@ -205,23 +199,5 @@ describe('Artifact', () => {
205
199
delete process . env . OPENSEARCH_SNAPSHOT_MANIFEST ;
206
200
} ) ;
207
201
} ) ;
208
-
209
- describe ( 'with latest unverified snapshot' , ( ) => {
210
- beforeEach ( ( ) => {
211
- process . env . OSD_OPENSEARCH_SNAPSHOT_USE_UNVERIFIED = 1 ;
212
- mockFetch ( MOCKS . valid ) ;
213
- } ) ;
214
-
215
- it ( 'should use the daily unverified URL when looking for a snapshot' , async ( ) => {
216
- await Artifact . getSnapshot ( 'oss' , MOCK_VERSION , log ) ;
217
- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual (
218
- `${ DAILY_SNAPSHOT_BASE_URL } /${ MOCK_VERSION } /manifest-latest.json`
219
- ) ;
220
- } ) ;
221
-
222
- afterEach ( ( ) => {
223
- delete process . env . OSD_OPENSEARCH_SNAPSHOT_USE_UNVERIFIED ;
224
- } ) ;
225
- } ) ;
226
202
} ) ;
227
203
} ) ;
0 commit comments