Moved serviceEndpoint() tests into abstract_serviceTest.
Also removed them from child classes. Change-Id: I291e0d418a4a87ea21bf829712935cd0b1fb6530
This commit is contained in:
@@ -122,72 +122,6 @@ describe('Glance', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("serviceEndpoint()", () => {
|
|
||||||
|
|
||||||
it("Should return a valid endpoint to the glance API.", (done) => {
|
|
||||||
const glance = new Glance(mockData.config);
|
|
||||||
|
|
||||||
fetchMock.mock(mockData.root());
|
|
||||||
|
|
||||||
glance.serviceEndpoint()
|
|
||||||
.then((endpoint) => {
|
|
||||||
expect(endpoint).toEqual('http://192.168.99.99:9292/v2/');
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((error) => done.fail(error));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should throw an exception if no endpoint is provided.", (done) => {
|
|
||||||
const glance = new Glance(mockData.config);
|
|
||||||
|
|
||||||
// Build an exception payload.
|
|
||||||
const mockOptions = mockData.root();
|
|
||||||
mockOptions.response.versions[0].links = [];
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
glance.serviceEndpoint()
|
|
||||||
.then((response) => done.fail(response))
|
|
||||||
.catch((error) => {
|
|
||||||
expect(error).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should throw an exception if no links array exists.", (done) => {
|
|
||||||
const glance = new Glance(mockData.config);
|
|
||||||
|
|
||||||
// Build an exception payload.
|
|
||||||
const mockOptions = mockData.root();
|
|
||||||
delete mockOptions.response.versions[0].links;
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
glance.serviceEndpoint()
|
|
||||||
.then((response) => done.fail(response))
|
|
||||||
.catch((error) => {
|
|
||||||
expect(error).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should cache its results", (done) => {
|
|
||||||
const glance = new Glance(mockData.config);
|
|
||||||
const mockOptions = mockData.root();
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
glance.serviceEndpoint()
|
|
||||||
.then(() => {
|
|
||||||
// Validate that the mock has only been invoked once
|
|
||||||
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
|
||||||
return glance.serviceEndpoint();
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((error) => done.fail(error));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("imageList()", () => {
|
describe("imageList()", () => {
|
||||||
let glance = null;
|
let glance = null;
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
* URLs to match the test data below.
|
* URLs to match the test data below.
|
||||||
*/
|
*/
|
||||||
const rootUrl = "http://example.com/";
|
const rootUrl = "http://example.com/";
|
||||||
const subUrl = `${rootUrl}/v1`;
|
const subUrl = `${rootUrl}v1`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mock list of supported versions for the below requests.
|
* A mock list of supported versions for the below requests.
|
||||||
@@ -50,7 +50,7 @@ function rootResponse() {
|
|||||||
id: "v2.3",
|
id: "v2.3",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v2/`,
|
href: `${rootUrl}v2/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -60,7 +60,7 @@ function rootResponse() {
|
|||||||
id: "v2.2",
|
id: "v2.2",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v2/`,
|
href: `${rootUrl}v2/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -70,7 +70,7 @@ function rootResponse() {
|
|||||||
id: "v2.1",
|
id: "v2.1",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v2/`,
|
href: `${rootUrl}v2/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -80,7 +80,7 @@ function rootResponse() {
|
|||||||
id: "v2.0",
|
id: "v2.0",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v2/`,
|
href: `${rootUrl}v2/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -90,7 +90,7 @@ function rootResponse() {
|
|||||||
id: "v1.1",
|
id: "v1.1",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v1/`,
|
href: `${rootUrl}v1/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -100,7 +100,7 @@ function rootResponse() {
|
|||||||
id: "v1.0",
|
id: "v1.0",
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: `${rootUrl}/v1/`,
|
href: `${rootUrl}v1/`,
|
||||||
rel: "self"
|
rel: "self"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@@ -106,72 +106,6 @@ describe('Keystone', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("serviceEndpoint()", () => {
|
|
||||||
|
|
||||||
it("Should return a valid endpoint to the keystone API.", (done) => {
|
|
||||||
const keystone = new Keystone(mockData.config);
|
|
||||||
|
|
||||||
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));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should throw an exception if no endpoint is provided.", (done) => {
|
|
||||||
const keystone = new Keystone(mockData.config);
|
|
||||||
|
|
||||||
// Build an exception payload.
|
|
||||||
const mockOptions = JSON.parse(JSON.stringify(mockData.root()));
|
|
||||||
mockOptions.response.versions.values[0].links = [];
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
keystone.serviceEndpoint()
|
|
||||||
.then((response) => done.fail(response))
|
|
||||||
.catch((error) => {
|
|
||||||
expect(error).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should throw an exception if no links array exists.", (done) => {
|
|
||||||
const keystone = new Keystone(mockData.config);
|
|
||||||
|
|
||||||
// Build an exception payload.
|
|
||||||
const mockOptions = JSON.parse(JSON.stringify(mockData.root()));
|
|
||||||
delete mockOptions.response.versions.values[0].links;
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
keystone.serviceEndpoint()
|
|
||||||
.then((response) => done.fail(response))
|
|
||||||
.catch((error) => {
|
|
||||||
expect(error).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should cache its results", (done) => {
|
|
||||||
const keystone = new Keystone(mockData.config);
|
|
||||||
const mockOptions = mockData.root();
|
|
||||||
fetchMock.mock(mockOptions);
|
|
||||||
|
|
||||||
keystone.serviceEndpoint()
|
|
||||||
.then(() => {
|
|
||||||
// Validate that the mock has only been invoked once
|
|
||||||
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
|
||||||
return keystone.serviceEndpoint();
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((error) => done.fail(error));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("tokenIssue()", () => {
|
describe("tokenIssue()", () => {
|
||||||
|
|
||||||
it("should 'just work' by using provided credentials from the config.", (done) => {
|
it("should 'just work' by using provided credentials from the config.", (done) => {
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import AbstractService from "../../../src/util/abstract_service";
|
import AbstractService from "../../../src/util/abstract_service";
|
||||||
import * as mockData from '../helpers/data/versions'; // Might as well use keystone
|
import * as mockData from "../helpers/data/versions";
|
||||||
import fetchMock from "fetch-mock";
|
import fetchMock from "fetch-mock"; // Might as well use service
|
||||||
|
|
||||||
describe('AbstractService', () => {
|
describe('AbstractService', () => {
|
||||||
|
|
||||||
@@ -173,4 +173,70 @@ describe('AbstractService', () => {
|
|||||||
.catch((error) => done.fail(error));
|
.catch((error) => done.fail(error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("serviceEndpoint()", () => {
|
||||||
|
|
||||||
|
it("Should return a valid endpoint to the API.", (done) => {
|
||||||
|
const service = new AbstractService(mockData.rootUrl, mockData.versions);
|
||||||
|
|
||||||
|
fetchMock.mock(mockData.rootResponse());
|
||||||
|
|
||||||
|
service.serviceEndpoint()
|
||||||
|
.then((endpoint) => {
|
||||||
|
expect(endpoint).toEqual('http://example.com/v2/');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should throw an exception if no endpoint is provided.", (done) => {
|
||||||
|
const service = new AbstractService(mockData.rootUrl, mockData.versions);
|
||||||
|
|
||||||
|
// Build an exception payload.
|
||||||
|
const mockOptions = mockData.rootResponse();
|
||||||
|
mockOptions.response.versions[0].links = [];
|
||||||
|
fetchMock.mock(mockOptions);
|
||||||
|
|
||||||
|
service.serviceEndpoint()
|
||||||
|
.then((response) => done.fail(response))
|
||||||
|
.catch((error) => {
|
||||||
|
expect(error).not.toBeNull();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should throw an exception if no links array exists.", (done) => {
|
||||||
|
const service = new AbstractService(mockData.rootUrl, mockData.versions);
|
||||||
|
|
||||||
|
// Build an exception payload.
|
||||||
|
const mockOptions = mockData.rootResponse();
|
||||||
|
delete mockOptions.response.versions[0].links;
|
||||||
|
fetchMock.mock(mockOptions);
|
||||||
|
|
||||||
|
service.serviceEndpoint()
|
||||||
|
.then((response) => done.fail(response))
|
||||||
|
.catch((error) => {
|
||||||
|
expect(error).not.toBeNull();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should cache its results", (done) => {
|
||||||
|
const service = new AbstractService(mockData.rootUrl, mockData.versions);
|
||||||
|
const mockOptions = mockData.rootResponse();
|
||||||
|
fetchMock.mock(mockOptions);
|
||||||
|
|
||||||
|
service.serviceEndpoint()
|
||||||
|
.then(() => {
|
||||||
|
// Validate that the mock has only been invoked once
|
||||||
|
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
||||||
|
return service.serviceEndpoint();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
expect(fetchMock.calls(mockOptions.name).length).toEqual(1);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user