OpenStack wrapper instance
Create wrapper class that takes clouds.yaml instance Change-Id: I37429b7bda35ca09efc3bf153841d4dc92d96b55
This commit is contained in:
parent
b033ad652e
commit
9677a06a2d
23
src/index.js
23
src/index.js
|
@ -1,3 +1,26 @@
|
||||||
export {default as Keystone} from './keystone';
|
export {default as Keystone} from './keystone';
|
||||||
export {default as Glance} from './glance';
|
export {default as Glance} from './glance';
|
||||||
export {default as Neutron} from './neutron';
|
export {default as Neutron} from './neutron';
|
||||||
|
|
||||||
|
export default class OpenStack {
|
||||||
|
/**
|
||||||
|
* Create wrapper class that takes clouds.yaml instance
|
||||||
|
*
|
||||||
|
* @param {{}} cloudConfig The configuration object for a specific cloud.
|
||||||
|
*/
|
||||||
|
constructor(cloudConfig) {
|
||||||
|
// Sanity checks.
|
||||||
|
if (!cloudConfig) {
|
||||||
|
throw new Error('A configuration is required.');
|
||||||
|
}
|
||||||
|
// Clone the config, so that this instance is immutable
|
||||||
|
// at runtime (no modifying the config after the fact).
|
||||||
|
cloudConfig = Object.assign({}, cloudConfig);
|
||||||
|
|
||||||
|
this.cloudConfig = cloudConfig;
|
||||||
|
}
|
||||||
|
getConfig() {
|
||||||
|
// Returns the config instance
|
||||||
|
return this.cloudConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Hewlett Packard Enterprise Development L.P.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* openstack class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock cloud configuration that matches our test data below. This is not a full clouds.yaml
|
||||||
|
* format, rather just the subsection pointing to a particular cloud.
|
||||||
|
*/
|
||||||
|
const cloudConfig = {
|
||||||
|
region_name: 'Region1',
|
||||||
|
auth: {
|
||||||
|
username: 'user',
|
||||||
|
password: 'pass',
|
||||||
|
project_name: 'js-openstack-lib',
|
||||||
|
auth_url: 'http://192.168.99.99/'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export {
|
||||||
|
cloudConfig as config,
|
||||||
|
};
|
|
@ -0,0 +1,32 @@
|
||||||
|
import OpenStack from "../../src/index";
|
||||||
|
import * as mockData from './helpers/data/openstack';
|
||||||
|
|
||||||
|
const FetchMock = require('fetch-mock');
|
||||||
|
|
||||||
|
describe("Simple test", () => {
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
FetchMock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should export a class", () => {
|
||||||
|
let t = new OpenStack(mockData.config);
|
||||||
|
expect(t).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should throw an error for an empty config", () => {
|
||||||
|
try {
|
||||||
|
let t = new OpenStack();
|
||||||
|
t.getConfig();
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toEqual('A configuration is required.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getConfig should returns the config", () => {
|
||||||
|
let openstack = new OpenStack(mockData.config);
|
||||||
|
let config = openstack.getConfig();
|
||||||
|
expect(config.region_name).toEqual('Region1');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue