2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 describe("app.services.Cluster", function() {
18 var Cluster = window.app.services.Cluster;
19 var test = window.test;
23 beforeEach( function() {
24 cluster = new Cluster({ base_uri: "http://localhost:9200/" });
27 describe( "when it is initialised", function() {
29 it("should have a localhost base_uri", function() {
30 expect( cluster.base_uri ).toBe( "http://localhost:9200/" );
33 it("should have no version", function() {
34 expect( cluster.version ).toBe( undefined );
39 describe( "setVersion()", function() {
41 it("have a version", function() {
42 cluster.setVersion( "1.12.3-5" );
43 expect( cluster.version ).toBe( "1.12.3-5" );
48 describe("versionAtLeast()", function() {
49 var vs = [ "0.0.3", "0.13.5", "0.90.3", "1.0.0", "1.1.0", "1.2.3", "1.12.4.rc2", "13.0.0" ];
51 it("should return true for versions that are less than or equal to the current version", function() {
52 cluster.setVersion("1.12.5");
53 expect( cluster.versionAtLeast("1.12.5" ) ).toBe( true );
54 expect( cluster.versionAtLeast("1.12.5rc2" ) ).toBe( true );
55 expect( cluster.versionAtLeast("1.12.5-6" ) ).toBe( true );
56 expect( cluster.versionAtLeast("1.12.5-6.beta7" ) ).toBe( true );
57 expect( cluster.versionAtLeast("1.12.4" ) ).toBe( true );
58 expect( cluster.versionAtLeast("0.12.4" ) ).toBe( true );
59 expect( cluster.versionAtLeast("1.1.8" ) ).toBe( true );
61 for( var i = 0; i < vs.length - 1; i++ ) {
62 cluster.setVersion( vs[i+1] );
63 expect( cluster.versionAtLeast( vs[i] ) ).toBe( true );
67 it("should return false for versions that are greater than the current version", function() {
68 cluster.setVersion("1.12.5");
69 expect( cluster.versionAtLeast("1.12.6" ) ).toBe( false );
70 expect( cluster.versionAtLeast("1.13.4" ) ).toBe( false );
71 expect( cluster.versionAtLeast("2.0.0" ) ).toBe( false );
73 for( var i = 0; i < vs.length - 1; i++ ) {
74 cluster.setVersion( vs[i] );
75 expect( cluster.versionAtLeast( vs[i+1] ) ).toBe( false );