blob: 9f116865ecda44ec4417842b1762b218b3567834 [file] [log] [blame]
Matteo Scandolo594dfbc2016-02-11 17:37:08 -08001(function () {
2 'use strict';
3
4 const computeNodes = [
5 {
6 humanReadableName: 'cp-1.teone.xos-pg0.clemson.cloudlab.us',
7 instances: [
8 {
9 instance_name: 'mysite_clients-3'
10 },
11 {
12 instance_name: 'mysite_clients-4'
13 },
14 {
15 instance_name: 'mysite_clients-5'
16 }
17 ]
18 },
19 {
20 humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us',
21 instances: [
22 {
23 instance_name: 'mysite_clients-1'
24 },
25 {
26 instance_name: 'mysite_clients-2'
27 }
28 ]
29 },
30 {
31 humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us',
32 instances: [
33 {
34 instance_name: 'mysite_clients-1'
35 },
36 {
37 instance_name: 'mysite_clients-2'
38 }
39 ]
40 }
41 ];
42
43 describe('The Rack Helper Service', () => {
44
Matteo Scandoloed9b4032016-02-16 12:50:50 -080045 var Service, Config;
46
47 // results
48 var cp1, cp2, cp3, rack, instancePos, nodePos;
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080049
50 beforeEach(module('xos.serviceTopology'));
51
52 // inject the rackHelper service
Matteo Scandoloed9b4032016-02-16 12:50:50 -080053 beforeEach(inject(function (_RackHelper_, _serviceTopologyConfig_) {
Matteo Scandolo594dfbc2016-02-11 17:37:08 -080054 // The injector unwraps the underscores (_) from around the parameter names when matching
55 Service = _RackHelper_;
Matteo Scandoloed9b4032016-02-16 12:50:50 -080056 Config = _serviceTopologyConfig_;
57
58 cp1 = {
59 width: (Config.instance.width * 2) + (Config.instance.margin * 3),
60 height: (Config.instance.height * 2) + (Config.instance.margin * 5) + Config.computeNode.labelHeight
61 };
62
63 cp2 = {
64 width: (Config.instance.width * 2) + (Config.instance.margin * 3),
65 height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight
66 };
67
68 cp3 = {
69 width: (Config.instance.width * 2) + (Config.instance.margin * 3),
70 height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight
71 };
72
73 rack = {
74 width: cp1.width + (Config.computeNode.margin * 2),
75 height: cp1.height + cp2.height + cp3.height + (Config.computeNode.margin * 4)
76 }
77
78 instancePos = [
79 {
80 x: Config.instance.margin,
81 y: Config.instance.margin + Service.getComputeNodeLabelSize()
82 },
83 {
84 x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1),
85 y: Config.instance.margin + Service.getComputeNodeLabelSize()
86 },
87 {
88 x: Config.instance.margin,
89 y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1)
90 },
91 {
92 x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1),
93 y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1)
94 }
95 ];
96
97 nodePos = [
98 {
99 x: Config.computeNode.margin,
100 y: Config.computeNode.margin
101 },
102 {
103 x: Config.computeNode.margin,
104 y: (Config.computeNode.margin * 2) + cp1.height
105 },
106 {
107 x: Config.computeNode.margin,
108 y: (Config.computeNode.margin * 3) + cp1.height + cp2.height
109 }
110 ]
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800111 }));
112
113 describe('Given a list of instances', () => {
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800114 it('should calculate the first Compute Node Size', () => {
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800115 const [width, height] = Service.getComputeNodeSize(computeNodes[0].instances);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800116 expect(width).toBe(cp1.width);
117 expect(height).toBe(cp1.height);
118 });
119
120 it('should calculate the second Compute Node Size', () => {
121 const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances);
122 expect(width).toBe(cp2.width);
123 expect(height).toBe(cp2.height);
124 });
125
126 it('should calculate the third Compute Node Size', () => {
127 const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances);
128 expect(width).toBe(cp3.width);
129 expect(height).toBe(cp3.height);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800130 });
131 });
132
133 describe('Given a list of Compute Nodes', () => {
134 it('should return rack size', () => {
135 const [width, height] = Service.getRackSize(computeNodes);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800136 expect(width).toBe(rack.width);
137 expect(height).toBe(rack.height);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800138 });
139 });
140
141 describe('Given an instance index', () => {
142 it('should return the position for first instance', () => {
143 const [x, y] = Service.getInstancePosition(0);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800144 expect(x).toBe(instancePos[0].x);
145 expect(y).toBe(instancePos[0].y);
146 })
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800147
148 it('should return the position for second instance', () => {
149 const [x, y] = Service.getInstancePosition(1);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800150 expect(x).toBe(instancePos[1].x);
151 expect(y).toBe(instancePos[1].y);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800152 });
153
154 it('should return the position for third instance', () => {
155 const [x, y] = Service.getInstancePosition(2);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800156 expect(x).toBe(instancePos[2].x);
157 expect(y).toBe(instancePos[2].y);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800158 });
159
160 it('should return the position for 4th instance', () => {
161 const [x, y] = Service.getInstancePosition(3);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800162 expect(x).toBe(instancePos[3].x);
163 expect(y).toBe(instancePos[3].y);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800164 });
165 });
166
167 describe('Given an ComputeNode index', () => {
168 it('should return the position for 1st node', () => {
169 const [x, y] = Service.getComputeNodePosition(computeNodes, 0);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800170 expect(x).toBe(nodePos[0].x);
171 expect(y).toBe(nodePos[0].y);
172 })
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800173
174 it('should return the position for 2st node', () => {
175 const [x, y] = Service.getComputeNodePosition(computeNodes, 1);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800176 expect(x).toBe(nodePos[1].x);
177 expect(y).toBe(nodePos[1].y);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800178 });
179
180 it('should return the position for 2st node', () => {
181 const [x, y] = Service.getComputeNodePosition(computeNodes, 2);
Matteo Scandoloed9b4032016-02-16 12:50:50 -0800182 expect(x).toBe(nodePos[2].x);
183 expect(y).toBe(nodePos[2].y);
Matteo Scandolo594dfbc2016-02-11 17:37:08 -0800184 });
185 });
186 });
187})();