lita-consul 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d9d08f566174b54aff99adc47f1b5ed4005f3ae
4
- data.tar.gz: 7c38b9852453a70228a1883847ef46f442733ba9
3
+ metadata.gz: 844421003794d177006fb04861b3bac4d30db932
4
+ data.tar.gz: d93e3f1d03baf6ad5c1b05eae68ec71707ab4193
5
5
  SHA512:
6
- metadata.gz: 0742652f2f71c7b74fc220251efc2d28a1300799399f41fd7fef900c1f2b68ba71f9504e4ad6f443a3db7ac836b06567c2ea580f4d0576a001396087b9c072fb
7
- data.tar.gz: 8cdfe7ec5ffb5bd7f851a2ff7e0de3771ef6716541407b62918ab8d69434b2c35678ecb29ff69f2111423635b9857ad373b02da91237996ac16aa1015c5ae63f
6
+ metadata.gz: a42a1bf02b78009ecdc219c1cc75a34d6f5110b6acf30e035893aca154279f12f08bbe23568e4c203f2bcf05bbbdce19fa6982854d90f58f335375471d17a38e
7
+ data.tar.gz: 8d9c85237ff3efa1ac2c3238bd9f70692043496a713ec980932792cd69a8d36f3a93234fb361e245c3d30a34af6a5d568f41892da7a5c49151a810e733647b97
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
4
  - 2.0.0
4
5
  script: bundle exec rake
5
6
  before_install:
6
7
  - gem update --system
8
+ - gem install bundler
7
9
  services:
8
10
  - redis-server
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # lita-consul
2
2
 
3
3
  [![Build Status](https://travis-ci.org/dpires/lita-consul.png?branch=master)](https://travis-ci.org/dpires/lita-consul)
4
- [![Coverage Status](https://coveralls.io/repos/dpires/lita-consul/badge.png)](https://coveralls.io/r/dpires/lita-consul)
4
+ [![Coverage Status](https://coveralls.io/repos/dpires/lita-consul/badge.svg?branch=master&service=github)](https://coveralls.io/github/dpires/lita-consul?branch=master)
5
5
 
6
- ***lita-consul*** is a handler for [Lita](https://github.com/litaio/lita) for interacting with [Consul](https://github.com/hashicorp/consul).
6
+ **lita-consul** is a handler for [Lita](https://github.com/litaio/lita) for interacting with [Consul](https://github.com/hashicorp/consul).
7
7
 
8
8
  ## Installation
9
9
 
@@ -14,6 +14,19 @@ module Lita
14
14
  route /^consul set ([a-zA-Z0-9\-\/_]+) ([a-zA-Z0-9\-\/_]+)/, :consul_set, command: true, help: {
15
15
  "consul set <key> <value>" => "Set <value> for <key>"
16
16
  }
17
+
18
+ route /^consul members/, :consul_members, command: true, help: {
19
+ "consul members" => "Return consul nodes"
20
+ }
21
+
22
+ def consul_members(response)
23
+ resp = http.get("#{api_url}/catalog/nodes/")
24
+ replies = []
25
+ MultiJson.load(resp.body).each do | node |
26
+ replies << "#{node['Node']} - #{node['Address']}"
27
+ end
28
+ response.reply replies.join("\n")
29
+ end
17
30
 
18
31
  def consul_get(response)
19
32
  key = response.matches.first.first
@@ -21,21 +34,6 @@ module Lita
21
34
  value = get_key_value(key)
22
35
  response.reply "#{key} = #{value}"
23
36
  end
24
- =begin
25
- begin
26
- resp = http.get("#{api_url}/kv/#{key}")
27
- obj = MultiJson.load(resp.body)
28
- unless obj[0]["Value"].nil?
29
- value = Base64.decode64(obj[0]["Value"])
30
- response.reply "#{key} = #{value}"
31
- else
32
- response.reply "#{key} = null"
33
- end
34
- rescue Faraday::ConnectionFailed=> e
35
- response.reply e.to_s
36
- end
37
- end
38
- =end
39
37
 
40
38
  def consul_set(response)
41
39
  key = response.matches.first.first
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-consul"
3
- spec.version = "0.0.2"
3
+ spec.version = "0.0.3"
4
4
  spec.authors = ["David Pires"]
5
5
  spec.email = ["david.pires@gmail.com"]
6
6
  spec.description = "Lita handler for Consul"
@@ -4,10 +4,12 @@ describe Lita::Handlers::Consul, lita_handler: true do
4
4
  describe 'lita routes' do
5
5
  it { is_expected.to route_command('consul get mykey').to(:consul_get) }
6
6
  it { is_expected.to route_command('consul set mykey myvalue').to(:consul_set) }
7
+ it { is_expected.to route_command('consul members').to(:consul_members) }
7
8
  end
8
9
 
9
10
  before do
10
11
  allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
12
+ allow_any_instance_of(Faraday::Connection).to receive(:put).and_return(response)
11
13
  end
12
14
 
13
15
  let(:response) { double("Faraday::Response") }
@@ -56,12 +58,30 @@ describe Lita::Handlers::Consul, lita_handler: true do
56
58
  }
57
59
  }
58
60
 
61
+ let(:members_response) {
62
+ %{
63
+ [
64
+ {"Node":"node1.node.consul","Address":"192.168.0.33"},
65
+ {"Node":"node2.node.consul","Address":"192.168.0.34"}
66
+ ]
67
+ }
68
+ }
69
+
70
+ describe '#consul members' do
71
+ it 'should list member nodes' do
72
+ allow(response).to receive(:body).and_return(members_response)
73
+ send_command('consul members')
74
+ expect(replies.last).to eq("node1.node.consul - 192.168.0.33\nnode2.node.consul - 192.168.0.34")
75
+ end
76
+ end
77
+
59
78
  describe '#consul get' do
60
79
  it 'return value for key' do
61
80
  allow(response).to receive(:body).and_return(single_key_response)
62
81
  send_command('consul get mykey')
63
82
  expect(replies.last).to eq("mykey = testing")
64
83
  end
84
+
65
85
  it 'return null value for key' do
66
86
  allow(response).to receive(:body).and_return(null_value_response)
67
87
  send_command('consul get mykey')
@@ -72,6 +92,7 @@ describe Lita::Handlers::Consul, lita_handler: true do
72
92
  describe '#consul set' do
73
93
  it 'set and return value for key' do
74
94
  allow(response).to receive(:body).and_return(new_key_response)
95
+ allow(response).to receive(:status).and_return(200)
75
96
  send_command('consul set myapp/config/url www.test.com')
76
97
  expect(replies.last).to eq("myapp/config/url = www.test.com")
77
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-consul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Pires