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