@cumulus/integration-tests 10.1.2 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Collections.js CHANGED
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  const isString = require('lodash/isString');
12
+ const pRetry = require('p-retry');
12
13
 
13
14
  const CollectionsApi = require('@cumulus/api-client/collections');
14
15
  const { randomId } = require('@cumulus/common/test-utils');
@@ -96,6 +97,43 @@ const buildRandomizedCollection = (overrides = {}) => ({
96
97
  ...overrides,
97
98
  });
98
99
 
100
+ /**
101
+ * Returns true if collection exists. False otherwise.
102
+ *
103
+ * @param {string} stackName - the prefix of the Cumulus stack
104
+ * @param {Object} collection - a Cumulus collection
105
+ * @returns {boolean}
106
+ */
107
+ const collectionExists = async (stackName, collection) => {
108
+ let response;
109
+ const exists = await pRetry(
110
+ async () => {
111
+ try {
112
+ response = await CollectionsApi.getCollection({
113
+ prefix: stackName,
114
+ collectionName: collection.name,
115
+ collectionVersion: collection.version,
116
+ pRetryOptions: {
117
+ retries: 0,
118
+ },
119
+ });
120
+ } catch (error) {
121
+ if (error.statusCode === 404) {
122
+ console.log(`Error: ${error}. Failed to get collection ${JSON.stringify(collection)}`);
123
+ return false;
124
+ }
125
+ throw error;
126
+ }
127
+ if (response.statusCode === 200) {
128
+ return true;
129
+ }
130
+ return false;
131
+ },
132
+ { retries: 5, minTimeout: 2000, maxTimeout: 2000 }
133
+ );
134
+ return exists;
135
+ };
136
+
99
137
  /**
100
138
  * Add a new collection to Cumulus
101
139
  *
@@ -103,12 +141,18 @@ const buildRandomizedCollection = (overrides = {}) => ({
103
141
  * @param {Object} collection - a Cumulus collection
104
142
  * @returns {Promise<undefined>}
105
143
  */
106
- const addCollection = async (stackName, collection) => {
107
- await CollectionsApi.deleteCollection({
108
- prefix: stackName,
109
- collectionName: collection.name,
110
- collectionVersion: collection.version,
111
- });
144
+ const addCollection = async (
145
+ stackName,
146
+ collection
147
+ ) => {
148
+ const exists = await collectionExists(stackName, collection);
149
+ if (exists) {
150
+ await CollectionsApi.deleteCollection({
151
+ prefix: stackName,
152
+ collectionName: collection.name,
153
+ collectionVersion: collection.version,
154
+ });
155
+ }
112
156
  const response = await CollectionsApi.createCollection({ prefix: stackName, collection });
113
157
  if (response.statusCode !== 200) {
114
158
  throw new Error(`Collections API did not return 200: ${JSON.stringify(response)}`);
package/Executions.js CHANGED
@@ -21,6 +21,7 @@ const EXECUTION_LIST_LIMIT = 50;
21
21
  * @param {string} prefix - the name of the Cumulus stack
22
22
  * @param {Function} matcher - a predicate function that takes an execution and determines if this
23
23
  * is the execution that is being searched for
24
+ * @param {Object} [queryParameters] - Optional query parameters
24
25
  * @param {Object} [options]
25
26
  * @param {integer} [options.timeout=0] - the number of seconds to wait for a matching execution
26
27
  * to be found
@@ -46,7 +47,7 @@ const findExecutionArn = async (prefix, matcher, queryParameters = { }, options
46
47
  let executions = JSON.parse(body);
47
48
  const { results } = executions;
48
49
  if (isNil(results)) {
49
- throw new Error('Not Found');
50
+ throw new Error('API executions list was empty');
50
51
  }
51
52
 
52
53
  execution = results.find(matcher);
@@ -68,7 +69,7 @@ const findExecutionArn = async (prefix, matcher, queryParameters = { }, options
68
69
  throw new pRetry.AbortError(error);
69
70
  }
70
71
 
71
- if (isNil(execution)) throw new Error('Not Found');
72
+ if (isNil(execution)) throw new Error('Execution never found in API');
72
73
 
73
74
  return execution.arn;
74
75
  },
package/README.md CHANGED
@@ -49,6 +49,7 @@ const Collections = require('@cumulus/integration-test/Collections');
49
49
  * [createCollection(prefix, [overrides])](#exp_module_Collections--createCollection) ⇒ <code>Promise.&lt;Object&gt;</code> ⏏
50
50
  * [~addCustomUrlPathToCollectionFiles(collection, customFilePath)](#module_Collections--createCollection..addCustomUrlPathToCollectionFiles) ⇒ <code>Array.&lt;Object&gt;</code>
51
51
  * [~buildCollection(params)](#module_Collections--createCollection..buildCollection) ⇒ <code>Object</code>
52
+ * [~collectionExists(stackName, collection)](#module_Collections--createCollection..collectionExists) ⇒ <code>boolean</code>
52
53
  * [~addCollection(stackName, collection)](#module_Collections--createCollection..addCollection) ⇒ <code>Promise.&lt;undefined&gt;</code>
53
54
  * [~addCollections(stackName, bucketName, dataDirectory, [postfix], [customFilePath], [duplicateHandling])](#module_Collections--createCollection..addCollections) ⇒ <code>Promise.&lt;Array.&lt;Object&gt;&gt;</code>
54
55
 
@@ -119,6 +120,18 @@ updated with the postfix.
119
120
  | params.duplicateHandling | <code>string</code> | duplicate handling setting |
120
121
  | params.postfix | <code>string</code> | a string to be appended to the end of the name |
121
122
 
123
+ <a name="module_Collections--createCollection..collectionExists"></a>
124
+
125
+ #### createCollection~collectionExists(stackName, collection) ⇒ <code>boolean</code>
126
+ Returns true if collection exists. False otherwise.
127
+
128
+ **Kind**: inner method of [<code>createCollection</code>](#exp_module_Collections--createCollection)
129
+
130
+ | Param | Type | Description |
131
+ | --- | --- | --- |
132
+ | stackName | <code>string</code> | the prefix of the Cumulus stack |
133
+ | collection | <code>Object</code> | a Cumulus collection |
134
+
122
135
  <a name="module_Collections--createCollection..addCollection"></a>
123
136
 
124
137
  #### createCollection~addCollection(stackName, collection) ⇒ <code>Promise.&lt;undefined&gt;</code>
@@ -157,12 +170,12 @@ const Executions = require('@cumulus/integration-test/Executions');
157
170
  ```
158
171
 
159
172
  * [Executions](#module_Executions)
160
- * [findExecutionArn(prefix, matcher, [options])](#exp_module_Executions--findExecutionArn) ⇒ <code>Promise.&lt;string&gt;</code> ⏏
173
+ * [findExecutionArn(prefix, matcher, [queryParameters], [options])](#exp_module_Executions--findExecutionArn) ⇒ <code>Promise.&lt;string&gt;</code> ⏏
161
174
  * [getExecutionWithStatus(params)](#exp_module_Executions--getExecutionWithStatus) ⇒ <code>Promise.&lt;Object&gt;</code> ⏏
162
175
 
163
176
  <a name="exp_module_Executions--findExecutionArn"></a>
164
177
 
165
- ### findExecutionArn(prefix, matcher, [options]) ⇒ <code>Promise.&lt;string&gt;</code> ⏏
178
+ ### findExecutionArn(prefix, matcher, [queryParameters], [options]) ⇒ <code>Promise.&lt;string&gt;</code> ⏏
166
179
  Find the execution ARN matching the `matcher` function
167
180
 
168
181
  **Kind**: Exported function
@@ -172,6 +185,7 @@ Find the execution ARN matching the `matcher` function
172
185
  | --- | --- | --- | --- |
173
186
  | prefix | <code>string</code> | | the name of the Cumulus stack |
174
187
  | matcher | <code>function</code> | | a predicate function that takes an execution and determines if this is the execution that is being searched for |
188
+ | [queryParameters] | <code>Object</code> | | Optional query parameters |
175
189
  | [options] | <code>Object</code> | | |
176
190
  | [options.timeout] | <code>integer</code> | <code>0</code> | the number of seconds to wait for a matching execution to be found |
177
191