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
This commit is contained in:
parent
c8f7503f88
commit
c8dfb08c50
|
@ -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) => {
|
||||
const glance = new Glance(mockData.config);
|
||||
|
||||
// Build an invalid mock object.
|
||||
const mockOptions = mockData.root();
|
||||
mockOptions.response.versions.shift();
|
||||
|
||||
fetchMock.mock(mockOptions);
|
||||
|
||||
glance.version()
|
||||
.then((response) => done.fail(response))
|
||||
.catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("Should NOT cache its results", (done) => {
|
||||
describe("serviceEndpoint()", () => {
|
||||
it("Should return a valid endpoint to the glance API.", (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);
|
||||
fetchMock.mock(mockData.root());
|
||||
|
||||
glance.serviceEndpoint()
|
||||
.then((endpoint) => {
|
||||
expect(endpoint).toEqual('http://192.168.99.99:9292/v2/');
|
||||
done();
|
||||
})
|
||||
.catch((error) => done.fail(error));
|
||||
|
|
|
@ -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) => {
|
||||
const keystone = new Keystone(mockData.config);
|
||||
|
||||
// Build an invalid mock object.
|
||||
const mockOptions = mockData.root();
|
||||
mockOptions.response.versions.values.shift();
|
||||
|
||||
fetchMock.mock(mockOptions);
|
||||
|
||||
keystone.version()
|
||||
.then((response) => done.fail(response))
|
||||
.catch((error) => {
|
||||
expect(error).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("Should NOT cache its results", (done) => {
|
||||
describe("serviceEndpoint()", () => {
|
||||
it("Should return a valid endpoint to the keystone API.", (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);
|
||||
fetchMock.mock(mockData.root());
|
||||
|
||||
keystone.serviceEndpoint()
|
||||
.then((endpoint) => {
|
||||
expect(endpoint).toEqual('http://192.168.99.99/identity_v2_admin/v3/');
|
||||
done();
|
||||
})
|
||||
.catch((error) => done.fail(error));
|
||||
|
|
Loading…
Reference in New Issue