fake_consul 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +8 -0
- data/circle.yml +10 -0
- data/fake_consul.gemspec +24 -0
- data/lib/fake_consul.rb +58 -0
- data/lib/fake_consul/server.rb +58 -0
- data/lib/fake_consul/version.rb +3 -0
- data/spec/fake_consul/server_spec.rb +50 -0
- data/spec/spec_helper.rb +5 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 087388aaf9c337a09d8fb6d05600b4cfd0a66446
|
4
|
+
data.tar.gz: 26c8da7c6240c1a49599cd817b338b1c4cfa6018
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eef9a1ead2f95216b0fa6a67a224f3ff547fecfda8dcce4b22dc9aabe67b6abcbbcabf0935eb82c921f26736bc032b35e95bc2571aaca82ce60d54b2da0f5534
|
7
|
+
data.tar.gz: e57f0dbf64dc5597f19a37586acf8494174ea1b79a29cdfff8051f8e367ca7d31a9662d9daa1c075389f96f04903e6050508dbeae3389d2eead9193e1edc98ca
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
## [Unreleased][unreleased]
|
6
|
+
|
7
|
+
## [v0.0.1] - 2015-11-27
|
8
|
+
### Initial implementation
|
9
|
+
- Adds simple consul client that fakes the consul server and provides state in an in-memory Hash.
|
10
|
+
- Client API conforms to that of [Diplomat::Kv](http://www.rubydoc.info/github/WeAreFarmGeek/diplomat/Diplomat/Kv) (See source here: [Diplomat](https://github.com/WeAreFarmGeek/diplomat) )
|
11
|
+
|
12
|
+
[unreleased]: https://github.com/teambox/cortana/compare/v0.0.1...HEAD
|
13
|
+
[v1.0.0]: https://github.com/teambox/cortana/tree/v0.0.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Redbooth
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# FakeConsul
|
2
|
+
|
3
|
+
Fakes a consul server. Usecase is for feature specs that need to maintain state written to consul kv store.
|
4
|
+
|
5
|
+
- Adds simple consul client that fakes the consul server and provides state in an in-memory Hash.
|
6
|
+
- Client API conforms to that of [Diplomat::Kv](http://www.rubydoc.info/github/WeAreFarmGeek/diplomat/Diplomat/Kv) (See source here: [Diplomat](https://github.com/WeAreFarmGeek/diplomat) )
|
7
|
+
|
8
|
+
[](https://circleci.com/gh/redbooth/fake_consul)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'fake_consul'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install fake_consul
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```require fake_consul```
|
27
|
+
|
28
|
+
In your specs:
|
29
|
+
|
30
|
+
```let(:fake_kv_store) { FakeConsul::Server.new }```
|
31
|
+
|
32
|
+
```before { allow(my_instance_or_class).to receive(:kv_client).and_return(fake_kv_store) }```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( http://github.com/redbooth/fake_consul/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/circle.yml
ADDED
data/fake_consul.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fake_consul/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fake_consul"
|
8
|
+
spec.version = FakeConsul::VERSION
|
9
|
+
spec.authors = ["Saimon Moore"]
|
10
|
+
spec.email = ["saimonmoore@gmail.com"]
|
11
|
+
spec.summary = %q{Fakes a consul server. Usecase is for feature specs using Diplomat client}
|
12
|
+
spec.description = %q{Fakes a consul server. Usecase is for feature specs using Diplomat client}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", "~> 3.2.21"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/lib/fake_consul.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "fake_consul/version"
|
2
|
+
|
3
|
+
module FakeConsul
|
4
|
+
class Server < HashWithIndifferentAccess
|
5
|
+
|
6
|
+
# Fake get
|
7
|
+
#
|
8
|
+
# Performs no http requests but stores data in local hash
|
9
|
+
#
|
10
|
+
# @param key [String]
|
11
|
+
# @param options [Hash]
|
12
|
+
# @options recurse [Boolean] wether to list all keys starting with this prefix
|
13
|
+
# @param not_found [Symbol] unused/unimplemented
|
14
|
+
# @param found [Symbol] not unused/unimplemented
|
15
|
+
# @return [Array<Hash>] e.g. [{key: 'foo', value: 'bar'}]
|
16
|
+
def get(key, options = nil, not_found = :reject, found = :return)
|
17
|
+
if options[:recurse]
|
18
|
+
find_keys_recursive(key)
|
19
|
+
else
|
20
|
+
consul_export_format(key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Fake put
|
25
|
+
#
|
26
|
+
# Performs no http requests but retrieves data from local hash
|
27
|
+
#
|
28
|
+
# @param key [String]
|
29
|
+
# @param options [Hash] unused/unimplemented
|
30
|
+
# @return [Boolean] true :trollface:
|
31
|
+
def kv_put(key, value, options = nil)
|
32
|
+
self[key] = value
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Returns the keys in the following format:
|
39
|
+
# [{key: `key`, value: 'bar'}]
|
40
|
+
# @return [Array<Hash>]
|
41
|
+
def consul_export_format(keys)
|
42
|
+
Array(keys).map do
|
43
|
+
{'key' => key, 'value' => self[key]}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns all keys that begin with the supplied `key`.
|
48
|
+
#
|
49
|
+
# @return [Array<Hash>] e.g. [{key: 'foo', value: 'bar'}]
|
50
|
+
def find_keys_recursive(key)
|
51
|
+
keys.select? do |_key|
|
52
|
+
_key.to_s.start_with?(key.to_s)
|
53
|
+
end.map do |_key|
|
54
|
+
consul_export_format(_key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module FakeConsul
|
2
|
+
class Server < HashWithIndifferentAccess
|
3
|
+
|
4
|
+
# Fake get
|
5
|
+
#
|
6
|
+
# Performs no http requests but stores data in local hash
|
7
|
+
#
|
8
|
+
# @param key [String]
|
9
|
+
# @param options [Hash]
|
10
|
+
# @options recurse [Boolean] wether to list all keys starting with this prefix
|
11
|
+
# @param not_found [Symbol] unused/unimplemented
|
12
|
+
# @param found [Symbol] not unused/unimplemented
|
13
|
+
# @return [Array<Hash>] e.g. [{key: 'foo', value: 'bar'}]
|
14
|
+
def get(key, options = nil, not_found = :reject, found = :return)
|
15
|
+
options ||= {}
|
16
|
+
|
17
|
+
if options[:recurse]
|
18
|
+
find_keys_recursive(key)
|
19
|
+
else
|
20
|
+
consul_export_format(key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Fake put
|
25
|
+
#
|
26
|
+
# Performs no http requests but retrieves data from local hash
|
27
|
+
#
|
28
|
+
# @param key [String]
|
29
|
+
# @param options [Hash] unused/unimplemented
|
30
|
+
# @return [Boolean] true :trollface:
|
31
|
+
def put(key, value, options = nil)
|
32
|
+
self[key] = value
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Returns the keys in the following format:
|
39
|
+
# [{key: `key`, value: 'bar'}]
|
40
|
+
# @return [Array<Hash>]
|
41
|
+
def consul_export_format(keys)
|
42
|
+
Array(keys).map do |key|
|
43
|
+
{'key' => key, 'value' => self[key]}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns all keys that begin with the supplied `key`.
|
48
|
+
#
|
49
|
+
# @return [Array<Hash>] e.g. [{key: 'foo', value: 'bar'}]
|
50
|
+
def find_keys_recursive(key)
|
51
|
+
self.keys.select do |_key|
|
52
|
+
_key.to_s.start_with?(key.to_s)
|
53
|
+
end.map do |_key|
|
54
|
+
consul_export_format(_key)
|
55
|
+
end.flatten
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe FakeConsul::Server do
|
4
|
+
subject { FakeConsul::Server.new }
|
5
|
+
|
6
|
+
describe '#put' do
|
7
|
+
it 'stores key into Hash' do
|
8
|
+
subject.put('foo', 'bar')
|
9
|
+
subject['foo'].must_equal 'bar'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns true' do
|
13
|
+
subject.put('foo', 'bar').must_equal true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#get' do
|
18
|
+
describe 'simple (no recursing)' do
|
19
|
+
before { subject.put('foo', 'bar') }
|
20
|
+
let(:expected_value) { [{'key' => 'foo', 'value' => 'bar'}] }
|
21
|
+
|
22
|
+
it 'retrieves key from Hash in an array' do
|
23
|
+
subject.get('foo').must_equal(expected_value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'with recursing' do
|
28
|
+
before do
|
29
|
+
subject.put('foo/bar/baz', 'baz')
|
30
|
+
subject.put('foo/bar/bif', 'bif')
|
31
|
+
subject.put('foo/bar/boz', 'boz')
|
32
|
+
subject.put('foo/boom/boz', 'boz')
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:expected_value) do
|
36
|
+
[
|
37
|
+
{'key' => 'foo/bar/baz', 'value' => 'baz'},
|
38
|
+
{'key' => 'foo/bar/bif', 'value' => 'bif'},
|
39
|
+
{'key' => 'foo/bar/boz', 'value' => 'boz'},
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:unexpected_value) { [{'key' => 'foo/boom/boz', 'value' => 'boz'}] }
|
44
|
+
|
45
|
+
it 'retrieves all keys beginning with supplied key from Hash in an array' do
|
46
|
+
subject.get('foo/bar/', recurse: true).must_equal(expected_value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fake_consul
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Saimon Moore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.21
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.21
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Fakes a consul server. Usecase is for feature specs using Diplomat client
|
56
|
+
email:
|
57
|
+
- saimonmoore@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- circle.yml
|
69
|
+
- fake_consul.gemspec
|
70
|
+
- lib/fake_consul.rb
|
71
|
+
- lib/fake_consul/server.rb
|
72
|
+
- lib/fake_consul/version.rb
|
73
|
+
- spec/fake_consul/server_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.14
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Fakes a consul server. Usecase is for feature specs using Diplomat client
|
99
|
+
test_files:
|
100
|
+
- spec/fake_consul/server_spec.rb
|
101
|
+
- spec/spec_helper.rb
|