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