summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDong Ma <winterma.dong@gmail.com>2016-09-13 18:31:34 +0800
committerDong Ma <winterma.dong@gmail.com>2016-09-28 07:38:46 -0700
commit9677a06a2dbce932e0d58e6cf8bf08ffaa9f69be (patch)
treefd2edd69a49ed2f0ecfd3193a99d7347e9a3a23f
parentb033ad652e35d71e7baf3dd1238991e067d2ec2c (diff)
OpenStack wrapper instance
Create wrapper class that takes clouds.yaml instance Change-Id: I37429b7bda35ca09efc3bf153841d4dc92d96b55
Notes
Notes (review): Code-Review+2: Corentin Ardeois <cardeois@internap.com> Workflow+1: Vitaly Kramskikh <vkramskikh@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 28 Sep 2016 16:29:24 +0000 Reviewed-on: https://review.openstack.org/369319 Project: openstack/js-openstack-lib Branch: refs/heads/master
-rw-r--r--src/index.js23
-rw-r--r--test/unit/helpers/data/openstack.js37
-rw-r--r--test/unit/indexTest.js32
3 files changed, 92 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
index bbff897..a5404a3 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,3 +1,26 @@
1export {default as Keystone} from './keystone'; 1export {default as Keystone} from './keystone';
2export {default as Glance} from './glance'; 2export {default as Glance} from './glance';
3export {default as Neutron} from './neutron'; 3export {default as Neutron} from './neutron';
4
5export default class OpenStack {
6 /**
7 * Create wrapper class that takes clouds.yaml instance
8 *
9 * @param {{}} cloudConfig The configuration object for a specific cloud.
10 */
11 constructor(cloudConfig) {
12 // Sanity checks.
13 if (!cloudConfig) {
14 throw new Error('A configuration is required.');
15 }
16 // Clone the config, so that this instance is immutable
17 // at runtime (no modifying the config after the fact).
18 cloudConfig = Object.assign({}, cloudConfig);
19
20 this.cloudConfig = cloudConfig;
21 }
22 getConfig() {
23 // Returns the config instance
24 return this.cloudConfig;
25 }
26}
diff --git a/test/unit/helpers/data/openstack.js b/test/unit/helpers/data/openstack.js
new file mode 100644
index 0000000..131aadd
--- /dev/null
+++ b/test/unit/helpers/data/openstack.js
@@ -0,0 +1,37 @@
1/*
2 * Copyright (c) 2016 Hewlett Packard Enterprise Development L.P.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
13 * the License for the specific language governing permissions and limitations
14 * under the License.
15 */
16
17/**
18 * This file contains test data for fetchMock, to simplify bootstrapping of unit tests for
19 * openstack class.
20 */
21
22/**
23 * Mock cloud configuration that matches our test data below. This is not a full clouds.yaml
24 * format, rather just the subsection pointing to a particular cloud.
25 */
26const cloudConfig = {
27 region_name: 'Region1',
28 auth: {
29 username: 'user',
30 password: 'pass',
31 project_name: 'js-openstack-lib',
32 auth_url: 'http://192.168.99.99/'
33 }
34};
35export {
36 cloudConfig as config,
37};
diff --git a/test/unit/indexTest.js b/test/unit/indexTest.js
new file mode 100644
index 0000000..829e46e
--- /dev/null
+++ b/test/unit/indexTest.js
@@ -0,0 +1,32 @@
1import OpenStack from "../../src/index";
2import * as mockData from './helpers/data/openstack';
3
4const FetchMock = require('fetch-mock');
5
6describe("Simple test", () => {
7
8 afterEach(() => {
9 FetchMock.reset();
10 });
11
12 it("should export a class", () => {
13 let t = new OpenStack(mockData.config);
14 expect(t).toBeDefined();
15 });
16
17 it("should throw an error for an empty config", () => {
18 try {
19 let t = new OpenStack();
20 t.getConfig();
21 } catch (e) {
22 expect(e.message).toEqual('A configuration is required.');
23 }
24 });
25
26 it("getConfig should returns the config", () => {
27 let openstack = new OpenStack(mockData.config);
28 let config = openstack.getConfig();
29 expect(config.region_name).toEqual('Region1');
30 });
31
32});