hashicorp-checkpoint 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/checkpoint.rb +5 -4
- data/lib/checkpoint/version.rb +1 -1
- data/spec/checkpoint_spec.rb +78 -13
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 604e2e85115ca7d44ade31c7cfa3a5bdf1d003cb
|
4
|
+
data.tar.gz: 379325a25d71edcd923c2a9fea987842086f1868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7edf03a9c7f81acd34543c9a8eb34bac66eeae83c8abc4cbc31a5ca3dbafa4eb14124df3e9ded0eb6dcca081f408ed793e3695e252c8bda306934f058d83df
|
7
|
+
data.tar.gz: 806138673d25c4c9f7ffc8ec56e11f044170df2cbb53c573dfc1ab5ce632761db366e94b4e8270a9b171e647e89a94154c0b238ae089dda31f5e16a4f6fc185c
|
data/lib/checkpoint.rb
CHANGED
@@ -9,7 +9,7 @@ require "checkpoint/platform"
|
|
9
9
|
require "checkpoint/version"
|
10
10
|
|
11
11
|
module Checkpoint
|
12
|
-
@@disabled =
|
12
|
+
@@disabled = !!ENV["CHECKPOINT_DISABLE"]
|
13
13
|
|
14
14
|
# Checks for the latest version information as well as alerts.
|
15
15
|
#
|
@@ -35,7 +35,7 @@ module Checkpoint
|
|
35
35
|
mtime = File.mtime(opts[:cache_file]).to_i
|
36
36
|
limit = Time.now.to_i - (60 * 60 * 24 * 2)
|
37
37
|
if mtime > limit
|
38
|
-
return build_check(File.read(opts[:cache_file]))
|
38
|
+
return build_check(File.read(opts[:cache_file]), "cached" => true)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Delete the file
|
@@ -101,7 +101,7 @@ module Checkpoint
|
|
101
101
|
end
|
102
102
|
|
103
103
|
build_check(resp.body)
|
104
|
-
rescue
|
104
|
+
rescue StandardError
|
105
105
|
# If we want errors, raise it
|
106
106
|
raise if opts[:raise_error]
|
107
107
|
|
@@ -116,9 +116,10 @@ module Checkpoint
|
|
116
116
|
|
117
117
|
protected
|
118
118
|
|
119
|
-
def self.build_check(response)
|
119
|
+
def self.build_check(response, extra_info={})
|
120
120
|
JSON.parse(response).tap do |result|
|
121
121
|
result["outdated"] = !!result["outdated"]
|
122
|
+
result.merge!(extra_info)
|
122
123
|
end
|
123
124
|
end
|
124
125
|
end
|
data/lib/checkpoint/version.rb
CHANGED
data/spec/checkpoint_spec.rb
CHANGED
@@ -4,6 +4,10 @@ require "helper"
|
|
4
4
|
|
5
5
|
describe Checkpoint do
|
6
6
|
describe ".check" do
|
7
|
+
before do
|
8
|
+
allow(ENV).to receive(:[]).and_return(nil)
|
9
|
+
end
|
10
|
+
|
7
11
|
context "with a proper request" do
|
8
12
|
subject do
|
9
13
|
described_class.check(
|
@@ -19,23 +23,84 @@ describe Checkpoint do
|
|
19
23
|
its(["product"]) { should eq("test") }
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
context "cache file" do
|
27
|
+
let(:path){ @path }
|
28
|
+
|
29
|
+
before do
|
30
|
+
tf = Tempfile.new("checkpoint")
|
31
|
+
tfpath = tf.path
|
32
|
+
tf.close
|
33
|
+
File.unlink(tfpath)
|
34
|
+
@path = tfpath
|
35
|
+
end
|
36
|
+
|
37
|
+
after{ File.unlink(path) if File.exist?(path) }
|
38
|
+
|
39
|
+
it "should cache things with cache_file" do
|
40
|
+
opts = {
|
41
|
+
product: "test",
|
42
|
+
version: "1.0",
|
43
|
+
cache_file: path,
|
44
|
+
}
|
45
|
+
|
46
|
+
# Just run it twice
|
47
|
+
c = described_class.check(opts)
|
48
|
+
c = described_class.check(opts)
|
49
|
+
|
50
|
+
expect(c["product"]).to eq("test")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should indicate cached result" do
|
54
|
+
opts = {
|
55
|
+
product: "test",
|
56
|
+
version: "1.0",
|
57
|
+
cache_file: path,
|
58
|
+
}
|
27
59
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
60
|
+
# Just run it twice
|
61
|
+
c = described_class.check(opts)
|
62
|
+
c = described_class.check(opts)
|
63
|
+
|
64
|
+
expect(c["cached"]).to eq(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with errors" do
|
69
|
+
let(:error_class){ StandardError }
|
70
|
+
let(:opts) {
|
71
|
+
{
|
72
|
+
product: "test",
|
73
|
+
version: "1.0"
|
74
|
+
}
|
32
75
|
}
|
76
|
+
before{ allow(Net::HTTP).to receive(:new).and_raise(error_class) }
|
77
|
+
|
78
|
+
it "should not raise error by default" do
|
79
|
+
expect(described_class.check(opts)).to be_nil
|
80
|
+
end
|
33
81
|
|
34
|
-
|
35
|
-
|
36
|
-
|
82
|
+
it "should raise error when option set" do
|
83
|
+
expect{ described_class.check(opts.merge(raise_error: true)) }.to raise_error(error_class)
|
84
|
+
end
|
85
|
+
|
86
|
+
context "with non-StandardError descendant exception" do
|
87
|
+
let(:error_class){ Interrupt }
|
88
|
+
|
89
|
+
it "should raise error by default" do
|
90
|
+
expect{ described_class.check(opts) }.to raise_error(error_class)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise error when option set" do
|
94
|
+
expect{ described_class.check(opts.merge(raise_error: true)) }.to raise_error(error_class)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
37
98
|
|
38
|
-
|
99
|
+
it "does not check when CHECKPOINT_DISABLE=1" do
|
100
|
+
allow(ENV).to receive(:[])
|
101
|
+
.with("CHECKPOINT_DISABLE")
|
102
|
+
.and_return(1)
|
103
|
+
expect(described_class.check).to be(nil)
|
39
104
|
end
|
40
105
|
end
|
41
106
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashicorp-checkpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitchell Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-its
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.0
|
69
69
|
description: Internal HashiCorp service to check version information
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
77
|
- Gemfile
|
78
78
|
- LICENSE.txt
|
79
79
|
- README.md
|
@@ -94,17 +94,17 @@ require_paths:
|
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.6.14
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Internal HashiCorp service to check version information.
|