Files
js-openstack-lib/test/unit/helpers/data/versions.js
Michael Krotscheck abfe901b5e AbstractService will try to detect the versions resource in more places.
We have no guarantees that the keystone service catalog will have the
root resource of any given service registered. As most versioned API
endpoints require tokens, we can reasonably assume that a 401 will
be encountered. This patch adds an extra check against the response
from the provided URL, and should a 401 be encountered, attempts
to resolve the versions from the root resource of the provided URL.

Change-Id: I655409f0eb9bfbd3489827db46faef026ede82f9
2016-09-22 07:36:39 -07:00

136 lines
2.8 KiB
JavaScript

/*
* Copyright (c) 2016 Michael Krotscheck.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This file contains test data for fetchMock, to simplify bootstrapping of unit tests for
* cross-service version detection.
*/
/**
* URLs to match the test data below.
*/
const rootUrl = "http://example.com/";
const subUrl = `${rootUrl}/v1`;
/**
* A mock list of supported versions for the below requests.
*
* @type {Array}
*/
const versions = [
'v2.3'
];
/**
* Build a new FetchMock configuration for the versions (root) endpoint.
*
* @returns {{}} A full FetchMock configuration for a versions resource.
*/
function rootResponse() {
return {
method: 'GET',
matcher: rootUrl,
response: {
versions: [
{
status: "CURRENT",
id: "v2.3",
links: [
{
href: `${rootUrl}/v2/`,
rel: "self"
}
]
},
{
status: "SUPPORTED",
id: "v2.2",
links: [
{
href: `${rootUrl}/v2/`,
rel: "self"
}
]
},
{
status: "SUPPORTED",
id: "v2.1",
links: [
{
href: `${rootUrl}/v2/`,
rel: "self"
}
]
},
{
status: "SUPPORTED",
id: "v2.0",
links: [
{
href: `${rootUrl}/v2/`,
rel: "self"
}
]
},
{
status: "SUPPORTED",
id: "v1.1",
links: [
{
href: `${rootUrl}/v1/`,
rel: "self"
}
]
},
{
status: "SUPPORTED",
id: "v1.0",
links: [
{
href: `${rootUrl}/v1/`,
rel: "self"
}
]
}
]
}
};
}
/**
* FetchMock configuration for a 401 response against the versioned API url.
*
* @param {int} httpStatus The HTTP status for the response.
* @returns {{}} A full FetchMock configuration a failing request..
*/
function subResponse(httpStatus = 401) {
return {
method: 'GET',
matcher: subUrl,
response: {
status: httpStatus
}
};
}
export {
rootUrl,
subUrl,
versions,
rootResponse,
subResponse
};