diff --git a/test/unit/glanceTest.js b/test/unit/glanceTest.js index d9162df..7511d50 100644 --- a/test/unit/glanceTest.js +++ b/test/unit/glanceTest.js @@ -14,9 +14,9 @@ * under the License. */ -import Glance from '../../src/glance.js'; -import * as mockData from './helpers/data/glance'; -import fetchMock from 'fetch-mock'; +import Glance from "../../src/glance.js"; +import * as mockData from "./helpers/data/glance"; +import fetchMock from "fetch-mock"; describe('Glance', () => { @@ -28,51 +28,10 @@ describe('Glance', () => { }); it('should throw an error for an empty config', () => { - try { - const glance = new Glance(); - glance.versions(); - } catch (e) { - expect(e.message).toEqual('An endpoint configuration is required.'); - } - }); - - describe("versions()", () => { - it("Should return a list of all versions available on this clouds' glance", (done) => { - const glance = new Glance(mockData.config); - - fetchMock.mock(mockData.root()); - - glance.versions() - .then((versions) => { - // Quick sanity check. - expect(versions.length).toBe(6); - done(); - }) - .catch((error) => done.fail(error)); - }); - - it("Should NOT cache its results", (done) => { - const glance = new Glance(mockData.config); - const mockOptions = mockData.root(); - - fetchMock.mock(mockOptions); - - glance.versions() - .then(() => { - // Validate that the mock has only been invoked once - expect(fetchMock.calls(mockOptions.name).length).toEqual(1); - return glance.versions(); - }) - .then(() => { - expect(fetchMock.calls(mockOptions.name).length).toEqual(2); - done(); - }) - .catch((error) => done.fail(error)); - }); + expect(() => new Glance()).toThrow(); }); describe("version()", () => { - it("Should return a supported version of the glance API.", (done) => { const glance = new Glance(mockData.config); @@ -85,37 +44,17 @@ describe('Glance', () => { }) .catch((error) => done.fail(error)); }); + }); - it("Should throw an exception if no supported version is found.", (done) => { + describe("serviceEndpoint()", () => { + it("Should return a valid endpoint to the glance API.", (done) => { const glance = new Glance(mockData.config); - // Build an invalid mock object. - const mockOptions = mockData.root(); - mockOptions.response.versions.shift(); + fetchMock.mock(mockData.root()); - fetchMock.mock(mockOptions); - - glance.version() - .then((response) => done.fail(response)) - .catch((error) => { - expect(error).not.toBeNull(); - done(); - }); - }); - - it("Should NOT cache its results", (done) => { - const glance = new Glance(mockData.config); - const mockOptions = mockData.root(); - fetchMock.mock(mockOptions); - - glance.version() - .then(() => { - // Validate that the mock has only been invoked once - expect(fetchMock.calls(mockOptions.name).length).toEqual(1); - return glance.version(); - }) - .then(() => { - expect(fetchMock.calls(mockOptions.name).length).toEqual(2); + glance.serviceEndpoint() + .then((endpoint) => { + expect(endpoint).toEqual('http://192.168.99.99:9292/v2/'); done(); }) .catch((error) => done.fail(error)); diff --git a/test/unit/keystoneTest.js b/test/unit/keystoneTest.js index 81c1faa..a1afdc2 100644 --- a/test/unit/keystoneTest.js +++ b/test/unit/keystoneTest.js @@ -12,15 +12,15 @@ describe('Keystone', () => { }); it('should throw an error for an empty config', () => { - try { - const keystone = new Keystone(); - keystone.tokenIssue(); - } catch (e) { - expect(e.message).toEqual('A configuration is required.'); - } + expect(() => new Keystone()).toThrow(); }); describe("versions()", () => { + + /** + * Keystone needs an explicit test, as it uses a slightly different data format + * than other services. + */ it("Should return a list of all versions available on this clouds' keystone", (done) => { const keystone = new Keystone(mockData.config); @@ -34,25 +34,6 @@ describe('Keystone', () => { }) .catch((error) => done.fail(error)); }); - - it("Should NOT cache its results", (done) => { - const keystone = new Keystone(mockData.config); - const mockOptions = mockData.root(); - - fetchMock.mock(mockOptions); - - keystone.versions() - .then(() => { - // Validate that the mock has only been invoked once - expect(fetchMock.calls(mockOptions.name).length).toEqual(1); - return keystone.versions(); - }) - .then(() => { - expect(fetchMock.calls(mockOptions.name).length).toEqual(2); - done(); - }) - .catch((error) => done.fail(error)); - }); }); describe("version()", () => { @@ -69,37 +50,17 @@ describe('Keystone', () => { }) .catch((error) => done.fail(error)); }); + }); - it("Should throw an exception if no supported version is found.", (done) => { + describe("serviceEndpoint()", () => { + it("Should return a valid endpoint to the keystone API.", (done) => { const keystone = new Keystone(mockData.config); - // Build an invalid mock object. - const mockOptions = mockData.root(); - mockOptions.response.versions.values.shift(); + fetchMock.mock(mockData.root()); - fetchMock.mock(mockOptions); - - keystone.version() - .then((response) => done.fail(response)) - .catch((error) => { - expect(error).not.toBeNull(); - done(); - }); - }); - - it("Should NOT cache its results", (done) => { - const keystone = new Keystone(mockData.config); - const mockOptions = mockData.root(); - fetchMock.mock(mockOptions); - - keystone.version() - .then(() => { - // Validate that the mock has only been invoked once - expect(fetchMock.calls(mockOptions.name).length).toEqual(1); - return keystone.version(); - }) - .then(() => { - expect(fetchMock.calls(mockOptions.name).length).toEqual(2); + keystone.serviceEndpoint() + .then((endpoint) => { + expect(endpoint).toEqual('http://192.168.99.99/identity_v2_admin/v3/'); done(); }) .catch((error) => done.fail(error));