Browse Source

Miscellaneous test cleanup.

This patch cleans up our constructor exception tests, and removes
old versions(), version(), and serviceEndpoint() tests that are
now handled in the parent class. Service specific tests have been
kept, and several tests to assert correct API behavior for specific
implementations have been added.

Change-Id: Ib42d94033ebb5613ee7e5c96654ab22f31fe4feb
Michael Krotscheck 2 years ago
parent
commit
c8dfb08c50
No account linked to committer's email address
2 changed files with 24 additions and 124 deletions
  1. 11
    72
      test/unit/glanceTest.js
  2. 13
    52
      test/unit/keystoneTest.js

+ 11
- 72
test/unit/glanceTest.js View File

@@ -14,9 +14,9 @@
14 14
  * under the License.
15 15
  */
16 16
 
17
-import Glance from '../../src/glance.js';
18
-import * as mockData from './helpers/data/glance';
19
-import fetchMock from 'fetch-mock';
17
+import Glance from "../../src/glance.js";
18
+import * as mockData from "./helpers/data/glance";
19
+import fetchMock from "fetch-mock";
20 20
 
21 21
 describe('Glance', () => {
22 22
 
@@ -28,51 +28,10 @@ describe('Glance', () => {
28 28
   });
29 29
 
30 30
   it('should throw an error for an empty config', () => {
31
-    try {
32
-      const glance = new Glance();
33
-      glance.versions();
34
-    } catch (e) {
35
-      expect(e.message).toEqual('An endpoint configuration is required.');
36
-    }
37
-  });
38
-
39
-  describe("versions()", () => {
40
-    it("Should return a list of all versions available on this clouds' glance", (done) => {
41
-      const glance = new Glance(mockData.config);
42
-
43
-      fetchMock.mock(mockData.root());
44
-
45
-      glance.versions()
46
-        .then((versions) => {
47
-          // Quick sanity check.
48
-          expect(versions.length).toBe(6);
49
-          done();
50
-        })
51
-        .catch((error) => done.fail(error));
52
-    });
53
-
54
-    it("Should NOT cache its results", (done) => {
55
-      const glance = new Glance(mockData.config);
56
-      const mockOptions = mockData.root();
57
-
58
-      fetchMock.mock(mockOptions);
59
-
60
-      glance.versions()
61
-        .then(() => {
62
-          // Validate that the mock has only been invoked once
63
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
64
-          return glance.versions();
65
-        })
66
-        .then(() => {
67
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(2);
68
-          done();
69
-        })
70
-        .catch((error) => done.fail(error));
71
-    });
31
+    expect(() => new Glance()).toThrow();
72 32
   });
73 33
 
74 34
   describe("version()", () => {
75
-
76 35
     it("Should return a supported version of the glance API.", (done) => {
77 36
       const glance = new Glance(mockData.config);
78 37
 
@@ -85,37 +44,17 @@ describe('Glance', () => {
85 44
         })
86 45
         .catch((error) => done.fail(error));
87 46
     });
47
+  });
88 48
 
89
-    it("Should throw an exception if no supported version is found.", (done) => {
49
+  describe("serviceEndpoint()", () => {
50
+    it("Should return a valid endpoint to the glance API.", (done) => {
90 51
       const glance = new Glance(mockData.config);
91 52
 
92
-      // Build an invalid mock object.
93
-      const mockOptions = mockData.root();
94
-      mockOptions.response.versions.shift();
95
-
96
-      fetchMock.mock(mockOptions);
97
-
98
-      glance.version()
99
-        .then((response) => done.fail(response))
100
-        .catch((error) => {
101
-          expect(error).not.toBeNull();
102
-          done();
103
-        });
104
-    });
105
-
106
-    it("Should NOT cache its results", (done) => {
107
-      const glance = new Glance(mockData.config);
108
-      const mockOptions = mockData.root();
109
-      fetchMock.mock(mockOptions);
53
+      fetchMock.mock(mockData.root());
110 54
 
111
-      glance.version()
112
-        .then(() => {
113
-          // Validate that the mock has only been invoked once
114
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
115
-          return glance.version();
116
-        })
117
-        .then(() => {
118
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(2);
55
+      glance.serviceEndpoint()
56
+        .then((endpoint) => {
57
+          expect(endpoint).toEqual('http://192.168.99.99:9292/v2/');
119 58
           done();
120 59
         })
121 60
         .catch((error) => done.fail(error));

+ 13
- 52
test/unit/keystoneTest.js View File

@@ -12,15 +12,15 @@ describe('Keystone', () => {
12 12
   });
13 13
 
14 14
   it('should throw an error for an empty config', () => {
15
-    try {
16
-      const keystone = new Keystone();
17
-      keystone.tokenIssue();
18
-    } catch (e) {
19
-      expect(e.message).toEqual('A configuration is required.');
20
-    }
15
+    expect(() => new Keystone()).toThrow();
21 16
   });
22 17
 
23 18
   describe("versions()", () => {
19
+
20
+    /**
21
+     * Keystone needs an explicit test, as it uses a slightly different data format
22
+     * than other services.
23
+     */
24 24
     it("Should return a list of all versions available on this clouds' keystone", (done) => {
25 25
       const keystone = new Keystone(mockData.config);
26 26
 
@@ -34,25 +34,6 @@ describe('Keystone', () => {
34 34
         })
35 35
         .catch((error) => done.fail(error));
36 36
     });
37
-
38
-    it("Should NOT cache its results", (done) => {
39
-      const keystone = new Keystone(mockData.config);
40
-      const mockOptions = mockData.root();
41
-
42
-      fetchMock.mock(mockOptions);
43
-
44
-      keystone.versions()
45
-        .then(() => {
46
-          // Validate that the mock has only been invoked once
47
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
48
-          return keystone.versions();
49
-        })
50
-        .then(() => {
51
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(2);
52
-          done();
53
-        })
54
-        .catch((error) => done.fail(error));
55
-    });
56 37
   });
57 38
 
58 39
   describe("version()", () => {
@@ -69,37 +50,17 @@ describe('Keystone', () => {
69 50
         })
70 51
         .catch((error) => done.fail(error));
71 52
     });
53
+  });
72 54
 
73
-    it("Should throw an exception if no supported version is found.", (done) => {
55
+  describe("serviceEndpoint()", () => {
56
+    it("Should return a valid endpoint to the keystone API.", (done) => {
74 57
       const keystone = new Keystone(mockData.config);
75 58
 
76
-      // Build an invalid mock object.
77
-      const mockOptions = mockData.root();
78
-      mockOptions.response.versions.values.shift();
79
-
80
-      fetchMock.mock(mockOptions);
81
-
82
-      keystone.version()
83
-        .then((response) => done.fail(response))
84
-        .catch((error) => {
85
-          expect(error).not.toBeNull();
86
-          done();
87
-        });
88
-    });
89
-
90
-    it("Should NOT cache its results", (done) => {
91
-      const keystone = new Keystone(mockData.config);
92
-      const mockOptions = mockData.root();
93
-      fetchMock.mock(mockOptions);
59
+      fetchMock.mock(mockData.root());
94 60
 
95
-      keystone.version()
96
-        .then(() => {
97
-          // Validate that the mock has only been invoked once
98
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
99
-          return keystone.version();
100
-        })
101
-        .then(() => {
102
-          expect(fetchMock.calls(mockOptions.name).length).toEqual(2);
61
+      keystone.serviceEndpoint()
62
+        .then((endpoint) => {
63
+          expect(endpoint).toEqual('http://192.168.99.99/identity_v2_admin/v3/');
103 64
           done();
104 65
         })
105 66
         .catch((error) => done.fail(error));

Loading…
Cancel
Save