Browse Source

Moved serviceEndpoint() tests into abstract_serviceTest.

Also removed them from child classes.

Change-Id: I291e0d418a4a87ea21bf829712935cd0b1fb6530
Michael Krotscheck 2 years ago
parent
commit
c8f7503f88
No account linked to committer's email address

+ 0
- 66
test/unit/glanceTest.js View File

@@ -122,72 +122,6 @@ describe('Glance', () => {
122 122
     });
123 123
   });
124 124
 
125
-  describe("serviceEndpoint()", () => {
126
-
127
-    it("Should return a valid endpoint to the glance API.", (done) => {
128
-      const glance = new Glance(mockData.config);
129
-
130
-      fetchMock.mock(mockData.root());
131
-
132
-      glance.serviceEndpoint()
133
-        .then((endpoint) => {
134
-          expect(endpoint).toEqual('http://192.168.99.99:9292/v2/');
135
-          done();
136
-        })
137
-        .catch((error) => done.fail(error));
138
-    });
139
-
140
-    it("Should throw an exception if no endpoint is provided.", (done) => {
141
-      const glance = new Glance(mockData.config);
142
-
143
-      // Build an exception payload.
144
-      const mockOptions = mockData.root();
145
-      mockOptions.response.versions[0].links = [];
146
-      fetchMock.mock(mockOptions);
147
-
148
-      glance.serviceEndpoint()
149
-        .then((response) => done.fail(response))
150
-        .catch((error) => {
151
-          expect(error).not.toBeNull();
152
-          done();
153
-        });
154
-    });
155
-
156
-    it("Should throw an exception if no links array exists.", (done) => {
157
-      const glance = new Glance(mockData.config);
158
-
159
-      // Build an exception payload.
160
-      const mockOptions = mockData.root();
161
-      delete mockOptions.response.versions[0].links;
162
-      fetchMock.mock(mockOptions);
163
-
164
-      glance.serviceEndpoint()
165
-        .then((response) => done.fail(response))
166
-        .catch((error) => {
167
-          expect(error).not.toBeNull();
168
-          done();
169
-        });
170
-    });
171
-
172
-    it("Should cache its results", (done) => {
173
-      const glance = new Glance(mockData.config);
174
-      const mockOptions = mockData.root();
175
-      fetchMock.mock(mockOptions);
176
-
177
-      glance.serviceEndpoint()
178
-        .then(() => {
179
-          // Validate that the mock has only been invoked once
180
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
181
-          return glance.serviceEndpoint();
182
-        })
183
-        .then(() => {
184
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
185
-          done();
186
-        })
187
-        .catch((error) => done.fail(error));
188
-    });
189
-  });
190
-
191 125
   describe("imageList()", () => {
192 126
     let glance = null;
193 127
 

+ 7
- 7
test/unit/helpers/data/versions.js View File

@@ -23,7 +23,7 @@
23 23
  * URLs to match the test data below.
24 24
  */
25 25
 const rootUrl = "http://example.com/";
26
-const subUrl = `${rootUrl}/v1`;
26
+const subUrl = `${rootUrl}v1`;
27 27
 
28 28
 /**
29 29
  * A mock list of supported versions for the below requests.
@@ -50,7 +50,7 @@ function rootResponse() {
50 50
           id: "v2.3",
51 51
           links: [
52 52
             {
53
-              href: `${rootUrl}/v2/`,
53
+              href: `${rootUrl}v2/`,
54 54
               rel: "self"
55 55
             }
56 56
           ]
@@ -60,7 +60,7 @@ function rootResponse() {
60 60
           id: "v2.2",
61 61
           links: [
62 62
             {
63
-              href: `${rootUrl}/v2/`,
63
+              href: `${rootUrl}v2/`,
64 64
               rel: "self"
65 65
             }
66 66
           ]
@@ -70,7 +70,7 @@ function rootResponse() {
70 70
           id: "v2.1",
71 71
           links: [
72 72
             {
73
-              href: `${rootUrl}/v2/`,
73
+              href: `${rootUrl}v2/`,
74 74
               rel: "self"
75 75
             }
76 76
           ]
@@ -80,7 +80,7 @@ function rootResponse() {
80 80
           id: "v2.0",
81 81
           links: [
82 82
             {
83
-              href: `${rootUrl}/v2/`,
83
+              href: `${rootUrl}v2/`,
84 84
               rel: "self"
85 85
             }
86 86
           ]
@@ -90,7 +90,7 @@ function rootResponse() {
90 90
           id: "v1.1",
91 91
           links: [
92 92
             {
93
-              href: `${rootUrl}/v1/`,
93
+              href: `${rootUrl}v1/`,
94 94
               rel: "self"
95 95
             }
96 96
           ]
@@ -100,7 +100,7 @@ function rootResponse() {
100 100
           id: "v1.0",
101 101
           links: [
102 102
             {
103
-              href: `${rootUrl}/v1/`,
103
+              href: `${rootUrl}v1/`,
104 104
               rel: "self"
105 105
             }
106 106
           ]

+ 0
- 66
test/unit/keystoneTest.js View File

@@ -106,72 +106,6 @@ describe('Keystone', () => {
106 106
     });
107 107
   });
108 108
 
109
-  describe("serviceEndpoint()", () => {
110
-
111
-    it("Should return a valid endpoint to the keystone API.", (done) => {
112
-      const keystone = new Keystone(mockData.config);
113
-
114
-      fetchMock.mock(mockData.root());
115
-
116
-      keystone.serviceEndpoint()
117
-        .then((endpoint) => {
118
-          expect(endpoint).toEqual('http://192.168.99.99/identity_v2_admin/v3/');
119
-          done();
120
-        })
121
-        .catch((error) => done.fail(error));
122
-    });
123
-
124
-    it("Should throw an exception if no endpoint is provided.", (done) => {
125
-      const keystone = new Keystone(mockData.config);
126
-
127
-      // Build an exception payload.
128
-      const mockOptions = JSON.parse(JSON.stringify(mockData.root()));
129
-      mockOptions.response.versions.values[0].links = [];
130
-      fetchMock.mock(mockOptions);
131
-
132
-      keystone.serviceEndpoint()
133
-        .then((response) => done.fail(response))
134
-        .catch((error) => {
135
-          expect(error).not.toBeNull();
136
-          done();
137
-        });
138
-    });
139
-
140
-    it("Should throw an exception if no links array exists.", (done) => {
141
-      const keystone = new Keystone(mockData.config);
142
-
143
-      // Build an exception payload.
144
-      const mockOptions = JSON.parse(JSON.stringify(mockData.root()));
145
-      delete mockOptions.response.versions.values[0].links;
146
-      fetchMock.mock(mockOptions);
147
-
148
-      keystone.serviceEndpoint()
149
-        .then((response) => done.fail(response))
150
-        .catch((error) => {
151
-          expect(error).not.toBeNull();
152
-          done();
153
-        });
154
-    });
155
-
156
-    it("Should cache its results", (done) => {
157
-      const keystone = new Keystone(mockData.config);
158
-      const mockOptions = mockData.root();
159
-      fetchMock.mock(mockOptions);
160
-
161
-      keystone.serviceEndpoint()
162
-        .then(() => {
163
-          // Validate that the mock has only been invoked once
164
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
165
-          return keystone.serviceEndpoint();
166
-        })
167
-        .then(() => {
168
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
169
-          done();
170
-        })
171
-        .catch((error) => done.fail(error));
172
-    });
173
-  });
174
-
175 109
   describe("tokenIssue()", () => {
176 110
 
177 111
     it("should 'just work' by using provided credentials from the config.", (done) => {

+ 68
- 2
test/unit/util/abstract_serviceTest.js View File

@@ -15,8 +15,8 @@
15 15
  */
16 16
 
17 17
 import AbstractService from "../../../src/util/abstract_service";
18
-import * as mockData from '../helpers/data/versions'; // Might as well use keystone
19
-import fetchMock from "fetch-mock";
18
+import * as mockData from "../helpers/data/versions";
19
+import fetchMock from "fetch-mock"; // Might as well use service
20 20
 
21 21
 describe('AbstractService', () => {
22 22
 
@@ -173,4 +173,70 @@ describe('AbstractService', () => {
173 173
         .catch((error) => done.fail(error));
174 174
     });
175 175
   });
176
+
177
+  describe("serviceEndpoint()", () => {
178
+
179
+    it("Should return a valid endpoint to the API.", (done) => {
180
+      const service = new AbstractService(mockData.rootUrl, mockData.versions);
181
+
182
+      fetchMock.mock(mockData.rootResponse());
183
+
184
+      service.serviceEndpoint()
185
+        .then((endpoint) => {
186
+          expect(endpoint).toEqual('http://example.com/v2/');
187
+          done();
188
+        })
189
+        .catch((error) => done.fail(error));
190
+    });
191
+
192
+    it("Should throw an exception if no endpoint is provided.", (done) => {
193
+      const service = new AbstractService(mockData.rootUrl, mockData.versions);
194
+
195
+      // Build an exception payload.
196
+      const mockOptions = mockData.rootResponse();
197
+      mockOptions.response.versions[0].links = [];
198
+      fetchMock.mock(mockOptions);
199
+
200
+      service.serviceEndpoint()
201
+        .then((response) => done.fail(response))
202
+        .catch((error) => {
203
+          expect(error).not.toBeNull();
204
+          done();
205
+        });
206
+    });
207
+
208
+    it("Should throw an exception if no links array exists.", (done) => {
209
+      const service = new AbstractService(mockData.rootUrl, mockData.versions);
210
+
211
+      // Build an exception payload.
212
+      const mockOptions = mockData.rootResponse();
213
+      delete mockOptions.response.versions[0].links;
214
+      fetchMock.mock(mockOptions);
215
+
216
+      service.serviceEndpoint()
217
+        .then((response) => done.fail(response))
218
+        .catch((error) => {
219
+          expect(error).not.toBeNull();
220
+          done();
221
+        });
222
+    });
223
+
224
+    it("Should cache its results", (done) => {
225
+      const service = new AbstractService(mockData.rootUrl, mockData.versions);
226
+      const mockOptions = mockData.rootResponse();
227
+      fetchMock.mock(mockOptions);
228
+
229
+      service.serviceEndpoint()
230
+        .then(() => {
231
+          // Validate that the mock has only been invoked once
232
+          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
233
+          return service.serviceEndpoint();
234
+        })
235
+        .then(() => {
236
+          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
237
+          done();
238
+        })
239
+        .catch((error) => done.fail(error));
240
+    });
241
+  });
176 242
 });

Loading…
Cancel
Save