summaryrefslogtreecommitdiffstats
path: root/vespaclient/src/perl/test/Yahoo/Vespa/Bin/GetClusterStateTest.pl
blob: 3339d872de5b95aa9d2f3224616661a915808834 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

use Test::More;
use strict;
use warnings;

BEGIN { use_ok( 'Yahoo::Vespa::Bin::GetClusterState' ); }
require_ok( 'Yahoo::Vespa::Bin::GetClusterState' );

use TestUtils::VespaTest;
use Yahoo::Vespa::Mocks::ClusterControllerMock;
use Yahoo::Vespa::Mocks::VespaModelMock;

# Set which application is called on assertRun / assertRunMatches calls
setApplication( \&getClusterState );

useColors(0);

&testSimple();
&testSyntaxPage();
&testClusterDown();

done_testing();

exit(0);

sub testSimple {
    my $stdout = <<EOS;

Cluster books:
books/storage/0: down
books/storage/1: up

Cluster music:
music/distributor/0: down
music/distributor/1: up
music/storage/0: retired
EOS
    assertRun("Default - no arguments", "", 0, $stdout, "");
}

sub testClusterDown {
    Yahoo::Vespa::Mocks::ClusterControllerMock::setClusterDown();
    Yahoo::Vespa::ClusterController::init();
    Yahoo::Vespa::Bin::GetClusterState::init();
    my $stdout = <<EOS;

Cluster books:
books/storage/0: down
books/storage/1: up

Cluster music is down. Too few nodes available.
music/distributor/0: down
music/distributor/1: up
music/storage/0: retired
EOS
    assertRun("Music cluster down", "", 0, $stdout, "");
}

sub testSyntaxPage {
    my $stdout = <<EOS;
EOS
    my $pat = qr/^Get the cluster state of a given cluster.*Usage:.*GetClusterState.*Options.*--help.*/s;
    assertRunMatches("Syntax page", "--help", 1, $pat, qr/^$/);
}