ztk 3.0.4 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ztk/profiler/core.rb +8 -3
- data/lib/ztk/version.rb +1 -1
- data/spec/ztk/ansi_spec.rb +3 -3
- data/spec/ztk/background_spec.rb +22 -22
- data/spec/ztk/base_spec.rb +1 -1
- data/spec/ztk/benchmark_spec.rb +13 -20
- data/spec/ztk/command_spec.rb +48 -61
- data/spec/ztk/config_spec.rb +16 -9
- data/spec/ztk/locator_spec.rb +3 -3
- data/spec/ztk/logger_spec.rb +40 -35
- data/spec/ztk/parallel_spec.rb +20 -20
- data/spec/ztk/profiler_spec.rb +100 -0
- data/spec/ztk/rescue_retry_spec.rb +18 -18
- data/spec/ztk/spinner_spec.rb +3 -3
- data/spec/ztk/ssh_spec.rb +87 -548
- data/spec/ztk/tcp_socket_check_spec.rb +11 -11
- data/spec/ztk/template_spec.rb +14 -13
- data/spec/ztk/ui_spec.rb +9 -9
- data/spec/ztk/version_spec.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1209eb8e5e2897a3911c0e7048080bc532b86c43
|
4
|
+
data.tar.gz: 0b41dee03dac4f105de394722dfa9608e98fc221
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d79fceb184898082b9db8edb3c040aee94edb10f07b25588daf7700c5813699652f3c7dc0973ef23f29a0e6e601e8d93590cc3c01e86e086603074f27d300789
|
7
|
+
data.tar.gz: 7759484bac6dff0b686c7ae43e54a6e60ca10bfbaa288b5f9522fd0acab96816d0212c89bc4e0de1f6ae5445576822ae83a2b7541362ec317d36f20151dcca17
|
data/lib/ztk/profiler/core.rb
CHANGED
@@ -11,6 +11,7 @@ module ZTK
|
|
11
11
|
|
12
12
|
def start
|
13
13
|
reset
|
14
|
+
@@start_time = Time.now.utc
|
14
15
|
|
15
16
|
true
|
16
17
|
end
|
@@ -22,7 +23,7 @@ module ZTK
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def reset
|
25
|
-
@@start_time =
|
26
|
+
@@start_time = nil
|
26
27
|
@@end_time = nil
|
27
28
|
@@timer_stack = Array.new
|
28
29
|
Timer.reset
|
@@ -54,8 +55,12 @@ module ZTK
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def total_time
|
57
|
-
|
58
|
-
|
58
|
+
if @@start_time.nil?
|
59
|
+
raise ProfilerError, "You must start the profiler in order to calculate a total time!"
|
60
|
+
else
|
61
|
+
stop
|
62
|
+
@@end_time - @@start_time
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def report(options={})
|
data/lib/ztk/version.rb
CHANGED
data/spec/ztk/ansi_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe "ZTK::ANSI Module" do
|
|
27
27
|
describe "module" do
|
28
28
|
|
29
29
|
it "should be ZTK::ANSI" do
|
30
|
-
subject.
|
30
|
+
expect(subject).to be ZTK::ANSI
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -36,11 +36,11 @@ end
|
|
36
36
|
|
37
37
|
describe "ZTK::ANSI Monkey-Patch String Class" do
|
38
38
|
|
39
|
-
subject
|
39
|
+
subject do
|
40
40
|
class String
|
41
41
|
include ZTK::ANSI
|
42
42
|
end
|
43
|
-
|
43
|
+
end
|
44
44
|
|
45
45
|
describe "class" do
|
46
46
|
|
data/spec/ztk/background_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe ZTK::Background do
|
|
27
27
|
describe "class" do
|
28
28
|
|
29
29
|
it "should be an instance of ZTK::Background" do
|
30
|
-
subject.
|
30
|
+
expect(subject).to be_an_instance_of ZTK::Background
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -35,7 +35,7 @@ describe ZTK::Background do
|
|
35
35
|
describe "behaviour" do
|
36
36
|
|
37
37
|
it "should throw an exception if the process method is called without a block" do
|
38
|
-
|
38
|
+
expect{ subject.process }.to raise_error ZTK::BackgroundError, "You must supply a block to the process method!"
|
39
39
|
end
|
40
40
|
|
41
41
|
describe "process" do
|
@@ -46,9 +46,9 @@ describe ZTK::Background do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
subject.wait
|
49
|
-
subject.result.
|
50
|
-
subject.result.
|
51
|
-
subject.result.
|
49
|
+
expect(subject.result).to be_kind_of Integer
|
50
|
+
expect(subject.result).to be > 0
|
51
|
+
expect(subject.result).not_to be == Process.pid
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -59,11 +59,11 @@ describe ZTK::Background do
|
|
59
59
|
subject.process do
|
60
60
|
sleep(WAIT_SMALL)
|
61
61
|
end
|
62
|
-
subject.alive
|
62
|
+
expect(subject.alive?).to be == true
|
63
63
|
|
64
64
|
subject.wait
|
65
|
-
subject.result.
|
66
|
-
subject.result.
|
65
|
+
expect(subject.result).to be_kind_of Integer
|
66
|
+
expect(subject.result).to be > 0
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should respond false when the process is no longer running" do
|
@@ -73,11 +73,11 @@ describe ZTK::Background do
|
|
73
73
|
subject.wait
|
74
74
|
sleep(WAIT_SMALL)
|
75
75
|
|
76
|
-
subject.alive
|
76
|
+
expect(subject.alive?).to be == false
|
77
77
|
|
78
|
-
subject.result.
|
79
|
-
subject.result.
|
80
|
-
subject.result.
|
78
|
+
expect(subject.result).to be_kind_of Integer
|
79
|
+
expect(subject.result).to be > 0
|
80
|
+
expect(subject.result).not_to be == Process.pid
|
81
81
|
end
|
82
82
|
|
83
83
|
end
|
@@ -89,12 +89,12 @@ describe ZTK::Background do
|
|
89
89
|
sleep(WAIT_SMALL)
|
90
90
|
WAIT_SMALL
|
91
91
|
end
|
92
|
-
subject.dead
|
92
|
+
expect(subject.dead?).to be false
|
93
93
|
|
94
94
|
subject.wait
|
95
|
-
subject.result.
|
96
|
-
subject.result.
|
97
|
-
subject.result.
|
95
|
+
expect(subject.result).to be_kind_of Integer
|
96
|
+
expect(subject.result).to be > 0
|
97
|
+
expect(subject.result).to be == WAIT_SMALL
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should respond true when the process is no longer running" do
|
@@ -104,11 +104,11 @@ describe ZTK::Background do
|
|
104
104
|
subject.wait
|
105
105
|
sleep(WAIT_SMALL)
|
106
106
|
|
107
|
-
subject.dead
|
107
|
+
expect(subject.dead?).to be true
|
108
108
|
|
109
|
-
subject.result.
|
110
|
-
subject.result.
|
111
|
-
subject.result.
|
109
|
+
expect(subject.result).to be_kind_of Integer
|
110
|
+
expect(subject.result).to be > 0
|
111
|
+
expect(subject.result).not_to be == Process.pid
|
112
112
|
end
|
113
113
|
|
114
114
|
end
|
@@ -127,8 +127,8 @@ describe ZTK::Background do
|
|
127
127
|
end
|
128
128
|
subject.wait
|
129
129
|
|
130
|
-
subject.result.
|
131
|
-
subject.result.hello_world.
|
130
|
+
expect(subject.result).to be_kind_of BackgroundMarshalTest
|
131
|
+
expect(subject.result.hello_world).to be == "Hello World"
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
data/spec/ztk/base_spec.rb
CHANGED
data/spec/ztk/benchmark_spec.rb
CHANGED
@@ -22,20 +22,14 @@ require "spec_helper"
|
|
22
22
|
|
23
23
|
describe ZTK::Benchmark do
|
24
24
|
|
25
|
-
|
26
|
-
@ui = ZTK::UI.new(
|
27
|
-
:stdout => StringIO.new,
|
28
|
-
:stderr => StringIO.new,
|
29
|
-
:stdin => StringIO.new
|
30
|
-
)
|
31
|
-
end
|
25
|
+
let(:ui) { ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :stdin => StringIO.new) }
|
32
26
|
|
33
27
|
subject { ZTK::Benchmark }
|
34
28
|
|
35
29
|
describe "class" do
|
36
30
|
|
37
31
|
it "should be ZTK::Benchmark" do
|
38
|
-
subject.
|
32
|
+
expect(subject).to be ZTK::Benchmark
|
39
33
|
end
|
40
34
|
|
41
35
|
end
|
@@ -43,44 +37,43 @@ describe ZTK::Benchmark do
|
|
43
37
|
describe "behaviour" do
|
44
38
|
|
45
39
|
it "should throw an exception if executed without a block" do
|
46
|
-
|
47
|
-
ZTK::Benchmark.bench
|
48
|
-
}.should raise_error ZTK::BenchmarkError, "You must supply a block!"
|
40
|
+
expect{ ZTK::Benchmark.bench }.to raise_error ZTK::BenchmarkError
|
49
41
|
end
|
50
42
|
|
51
43
|
it "should return the benchmark of the given block" do
|
52
44
|
mark = ZTK::Benchmark.bench do
|
53
45
|
sleep(0.1)
|
54
46
|
end
|
55
|
-
mark.
|
47
|
+
expect(mark).to be_an_instance_of Float
|
56
48
|
end
|
57
49
|
|
58
50
|
it "should not throw an exception if executed with a message but without a mark" do
|
59
|
-
expect
|
60
|
-
ZTK::Benchmark.bench(:ui =>
|
51
|
+
expect{
|
52
|
+
ZTK::Benchmark.bench(:ui => ui, :message => "Hello World") do
|
53
|
+
sleep(0.1)
|
61
54
|
end
|
62
55
|
}.not_to raise_error
|
63
56
|
end
|
64
57
|
|
65
58
|
it "should not throw an exception if executed without a message but with a mark" do
|
66
|
-
expect
|
67
|
-
ZTK::Benchmark.bench(:ui =>
|
59
|
+
expect{
|
60
|
+
ZTK::Benchmark.bench(:ui => ui, :mark => "%0.4f") do
|
68
61
|
end
|
69
62
|
}.not_to raise_error
|
70
63
|
end
|
71
64
|
|
72
65
|
it "should not write to STDOUT if not given a message or mark" do
|
73
|
-
ZTK::Benchmark.bench(:ui =>
|
66
|
+
ZTK::Benchmark.bench(:ui => ui, :use_spinner => false) do
|
74
67
|
sleep(0.1)
|
75
68
|
end
|
76
|
-
|
69
|
+
expect(ui.stdout.size).to be == 0
|
77
70
|
end
|
78
71
|
|
79
72
|
it "should write to STDOUT if given a message and mark" do
|
80
|
-
ZTK::Benchmark.bench(:ui =>
|
73
|
+
ZTK::Benchmark.bench(:ui => ui, :message => "Hello World", :mark => "%0.4f") do
|
81
74
|
sleep(0.1)
|
82
75
|
end
|
83
|
-
|
76
|
+
expect(ui.stdout.size).to be > 0
|
84
77
|
end
|
85
78
|
|
86
79
|
end
|
data/spec/ztk/command_spec.rb
CHANGED
@@ -22,20 +22,14 @@ require "spec_helper"
|
|
22
22
|
|
23
23
|
describe ZTK::Command do
|
24
24
|
|
25
|
-
|
26
|
-
@ui = ZTK::UI.new(
|
27
|
-
:stdout => StringIO.new,
|
28
|
-
:stderr => StringIO.new,
|
29
|
-
:stdin => StringIO.new
|
30
|
-
)
|
31
|
-
end
|
25
|
+
let(:ui) { ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :stdin => StringIO.new) }
|
32
26
|
|
33
|
-
subject { ZTK::Command.new
|
27
|
+
subject { ZTK::Command.new }
|
34
28
|
|
35
29
|
describe "class" do
|
36
30
|
|
37
31
|
it "should be an instance of ZTK::Command" do
|
38
|
-
subject.
|
32
|
+
expect(subject).to be_an_instance_of ZTK::Command
|
39
33
|
end
|
40
34
|
|
41
35
|
end
|
@@ -45,86 +39,80 @@ describe ZTK::Command do
|
|
45
39
|
describe "execute" do
|
46
40
|
|
47
41
|
it "should be able to execute the command \"hostname\"" do
|
48
|
-
subject.config
|
49
|
-
|
50
|
-
end
|
42
|
+
subject.config.ui = ui
|
43
|
+
|
51
44
|
hostname = %x(hostname).chomp
|
52
45
|
status = subject.exec("hostname")
|
53
|
-
status.exit_code.
|
54
|
-
|
55
|
-
|
46
|
+
expect(status.exit_code).to be == 0
|
47
|
+
ui.stdout.rewind
|
48
|
+
expect(ui.stdout.read.chomp).to match(hostname)
|
56
49
|
end
|
57
50
|
|
58
51
|
it "should timeout after the period specified" do
|
59
52
|
subject.config do |config|
|
60
|
-
config.ui =
|
53
|
+
config.ui = ui
|
61
54
|
config.timeout = WAIT_SMALL
|
62
55
|
end
|
63
56
|
hostname = %x(hostname).chomp
|
64
|
-
|
57
|
+
expect{ subject.exec("hostname ; sleep 10") }.to raise_error ZTK::CommandError
|
65
58
|
end
|
66
59
|
|
67
60
|
it "should throw an exception if the exit status is not as expected" do
|
68
|
-
subject.config
|
69
|
-
|
70
|
-
|
71
|
-
lambda { subject.exec("/bin/bash -c 'exit 64'") }.should raise_error ZTK::CommandError
|
61
|
+
subject.config.ui = ui
|
62
|
+
|
63
|
+
expect{ subject.exec("/bin/bash -c 'exit 64'") }.to raise_error ZTK::CommandError
|
72
64
|
end
|
73
65
|
|
74
66
|
it "should return a instance of an OpenStruct object" do
|
75
|
-
subject.config
|
76
|
-
|
77
|
-
end
|
67
|
+
subject.config.ui = ui
|
68
|
+
|
78
69
|
result = subject.exec(%q{echo "Hello World"})
|
79
|
-
result.
|
70
|
+
expect(result).to be_an_instance_of OpenStruct
|
80
71
|
end
|
81
72
|
|
82
73
|
it "should return the exit code" do
|
83
|
-
subject.config
|
84
|
-
|
85
|
-
end
|
74
|
+
subject.config.ui = ui
|
75
|
+
|
86
76
|
data = 64
|
87
77
|
|
88
|
-
result = subject.exec(%
|
89
|
-
result.exit_code.
|
78
|
+
result = subject.exec(%{exit #{data}}, :exit_code => data)
|
79
|
+
expect(result.exit_code).to be == data
|
90
80
|
end
|
91
81
|
|
92
82
|
it "should return the output" do
|
93
|
-
subject.config
|
94
|
-
|
95
|
-
end
|
83
|
+
subject.config.ui = ui
|
84
|
+
|
96
85
|
data = "Hello World @ #{Time.now.utc}"
|
97
86
|
|
98
|
-
result = subject.exec(%
|
99
|
-
result.output.match(data)
|
87
|
+
result = subject.exec(%{echo "#{data}"})
|
88
|
+
expect(result.output).to match(data)
|
100
89
|
end
|
101
90
|
|
102
91
|
it "should allow us to change the expected exit code" do
|
103
|
-
subject.config
|
104
|
-
|
105
|
-
end
|
92
|
+
subject.config.ui = ui
|
93
|
+
|
106
94
|
data = 32
|
107
|
-
result = subject.exec(%
|
95
|
+
result = subject.exec(%{exit #{data}}, :exit_code => data)
|
96
|
+
expect(result.exit_code).to be == data
|
108
97
|
end
|
109
98
|
|
110
99
|
describe "stdout" do
|
111
100
|
|
112
101
|
it "should capture STDOUT and send it to the appropriate pipe" do
|
113
|
-
subject.config
|
114
|
-
|
115
|
-
end
|
102
|
+
subject.config.ui = ui
|
103
|
+
|
116
104
|
data = "Hello World @ #{Time.now.utc}"
|
117
105
|
|
118
|
-
subject.exec(%
|
106
|
+
subject.exec(%{echo "#{data}" >&1})
|
119
107
|
|
120
|
-
|
121
|
-
|
108
|
+
ui.stdout.rewind
|
109
|
+
expect(ui.stdout.read).to match(data)
|
122
110
|
|
123
|
-
|
124
|
-
|
111
|
+
ui.stderr.rewind
|
112
|
+
expect(ui.stderr.read).to be_empty
|
125
113
|
|
126
|
-
|
127
|
-
|
114
|
+
ui.stdin.rewind
|
115
|
+
expect(ui.stdin.read).to be_empty
|
128
116
|
end
|
129
117
|
|
130
118
|
end
|
@@ -132,21 +120,20 @@ describe ZTK::Command do
|
|
132
120
|
describe "stderr" do
|
133
121
|
|
134
122
|
it "should capture STDERR and send it to the appropriate pipe" do
|
135
|
-
subject.config
|
136
|
-
|
137
|
-
end
|
123
|
+
subject.config.ui = ui
|
124
|
+
|
138
125
|
data = "Hello World @ #{Time.now.utc}"
|
139
126
|
|
140
|
-
subject.exec(%
|
127
|
+
subject.exec(%{echo "#{data}" >&2})
|
141
128
|
|
142
|
-
|
143
|
-
|
129
|
+
ui.stdout.rewind
|
130
|
+
expect(ui.stdout.read).to be_empty
|
144
131
|
|
145
|
-
|
146
|
-
|
132
|
+
ui.stderr.rewind
|
133
|
+
expect(ui.stderr.read).to match(data)
|
147
134
|
|
148
|
-
|
149
|
-
|
135
|
+
ui.stdin.rewind
|
136
|
+
expect(ui.stdin.read).to be_empty
|
150
137
|
end
|
151
138
|
end
|
152
139
|
|
@@ -155,7 +142,7 @@ describe ZTK::Command do
|
|
155
142
|
describe "upload" do
|
156
143
|
|
157
144
|
it "should raise a 'Not Supported' exception when attempting to upload" do
|
158
|
-
|
145
|
+
expect{ subject.upload("abc", "123") }.to raise_error ZTK::CommandError
|
159
146
|
end
|
160
147
|
|
161
148
|
end
|
@@ -163,7 +150,7 @@ describe ZTK::Command do
|
|
163
150
|
describe "download" do
|
164
151
|
|
165
152
|
it "should raise a 'Not Supported' exception when attempting to download" do
|
166
|
-
|
153
|
+
expect{ subject.download("abc", "123") }.to raise_error ZTK::CommandError
|
167
154
|
end
|
168
155
|
|
169
156
|
end
|