-
Notifications
You must be signed in to change notification settings - Fork 23
/
sharedflow.js
155 lines (133 loc) · 5.57 KB
/
sharedflow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// sharedflow.js
// ------------------------------------------------------------------
//
// Tests for Sharedflow operations.
//
// Copyright 2017-2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// created: Sat Apr 29 09:17:48 2017
// last saved: <2021-March-22 17:33:58>
/* global describe, faker, it, path, before */
describe('Sharedflow', function() {
const common = require('./common'),
fs = require('fs'),
resourceDir = "./test/resources/sharedflows",
dateVal = new Date().valueOf(),
namePrefix = 'apigee-edge-js-test-' + dateVal;
this.timeout(common.testTimeout);
this.slow(common.slowThreshold);
common.connectApigee(function(org) {
describe('sf-import-from-zip-and-get', function() {
var sharedFlowList;
var zipFileList;
var envList;
before(function(done){
const actualPath = path.resolve(resourceDir);
fs.readdir(actualPath, function(e, items) {
assert.isNull(e, "error getting zips: " + JSON.stringify(e));
var re = new RegExp('^sharedflow-.+\.zip$');
items = items.filter(function(item){ return item.match(re);});
zipFileList = items.map(function(item){ return path.resolve( path.join(resourceDir, item));});
org.environments.get(function(e, result) {
assert.isNull(e, "error listing: " + JSON.stringify(e));
envList = result;
done();
});
});
});
it('should import sharedflow zips into an org', () => {
this.timeout(15000);
//org.conn.verbosity = 2;
let reducer = (p, zip) =>
p.then( () => org.sharedflows.importFromZip({name: namePrefix + '-fromzip-' + faker.random.alphaNumeric(12), zipArchive:zip})
// .then ( (result) => console.log(JSON.stringify(result)))
);
return zipFileList
.reduce(reducer, Promise.resolve());
});
it('should import sharedflow zips via the simple method', () => {
this.timeout(15000);
let reducer = (p, zip) =>
p.then( () => org.sharedflows.import({name: namePrefix + '-fromzip-' + faker.random.alphaNumeric(12), source:zip}) );
return zipFileList
.reduce(reducer, Promise.resolve());
});
// DO NOT want to factor these out.
// These tests need SFs to exist, and some orgs do not have them.
it('should list all sharedflows for an org', function(done) {
org.sharedflows.get({}, function(e, result){
assert.isNull(e, "error getting sharedflows: " + JSON.stringify(e));
assert.isDefined(result.length, "sharedflow list");
assert.isAbove(result.length, 1, "length of sharedflow list");
sharedFlowList = result;
done();
});
});
it('should get a few randomly-selected sharedFlows', function(done) {
assert.isTrue(sharedFlowList && sharedFlowList.length>0);
let fn = (item, ix, list) =>
org.sharedflows.get({name:item})
.then(($) => assert.equal(item, $.name, "sharedflow name"));
common.selectNRandom(sharedFlowList, 4, fn, done);
});
it('should export a few sharedflows', function(done) {
assert.isTrue(sharedFlowList && sharedFlowList.length>0);
let fn = (item, ix, list) =>
org.sharedflows.export({name:item})
.then(($) => assert.isTrue($.filename.startsWith('sharedflow-'), "file name"));
common.selectNRandom(sharedFlowList, 4, fn, done);
});
it('should fail to get a non-existent sharedflow', function(done) {
var fakeName = 'sharedflow-' + faker.random.alphaNumeric(23);
org.sharedflows.get({name:fakeName}, function(e, result){
assert.isNotNull(e, "the expected error did not occur");
done();
});
});
it('should delete test sharedflows previously imported into this org', function(done) {
org.sharedflows.get({}, function(e, sharedflows) {
var numDone = 0, L = 0;
let tick = function() { if (++numDone >= L) { done(); } };
assert.isNull(e, "error getting sharedflows: " + JSON.stringify(e));
assert.isAbove(sharedflows.length, 1, "length of SF list");
L = sharedflows.length;
sharedflows.forEach(function(sf) {
if (sf.startsWith(namePrefix + '-fromzip-')) {
org.sharedflows.del({name:sf}, function(e, proxies) {
assert.isNull(e, "error deleting sharedflow: " + JSON.stringify(e));
tick();
});
}
else { tick(); }
});
});
});
});
// describe('get', function() {
//
// before(function(done){
// org.sharedflows.get({}, function(e, result){
// assert.isNull(e, "error getting sharedflows: " + JSON.stringify(e));
// assert.isDefined(result.length, "sharedflow list");
// assert.isAbove(result.length, 1, "length of sharedflow list");
// sharedFlowList = result;
// done();
// });
// });
//
//
// });
});
});