influxdb-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -0
  3. data/README.md +2 -0
  4. data/influxdb/Dockerfile.0.7.3 +8 -0
  5. data/influxdb/Dockerfile.0.8.3 +8 -0
  6. data/influxdb/Dockerfile.0.8.8 +8 -0
  7. data/lib/influxdb/api.rb +3 -0
  8. data/lib/influxdb/api/client.rb +5 -1
  9. data/lib/influxdb/api/database.rb +14 -2
  10. data/lib/influxdb/api/namespaces/base.rb +7 -0
  11. data/lib/influxdb/api/namespaces/cluster_admins.rb +4 -0
  12. data/lib/influxdb/api/namespaces/continuous_queries.rb +28 -4
  13. data/lib/influxdb/api/namespaces/databases.rb +4 -0
  14. data/lib/influxdb/api/namespaces/series.rb +3 -0
  15. data/lib/influxdb/api/namespaces/shards.rb +15 -0
  16. data/lib/influxdb/api/namespaces/users.rb +7 -0
  17. data/lib/influxdb/api/server_version.rb +6 -2
  18. data/lib/influxdb/api/version.rb +1 -1
  19. data/spec/intergrations/cluster_admins_spec.rb +75 -0
  20. data/spec/intergrations/continuous_queries_spec.rb +106 -0
  21. data/spec/intergrations/databases_spec.rb +68 -0
  22. data/spec/intergrations/series_spec.rb +104 -0
  23. data/spec/intergrations/servers_spec.rb +35 -0
  24. data/spec/intergrations/shard_spaces_spec.rb +126 -0
  25. data/spec/intergrations/shards_spec.rb +85 -0
  26. data/spec/intergrations/users_0_7_3_spec.rb +104 -0
  27. data/spec/intergrations/users_spec.rb +124 -0
  28. data/spec/lib/influxdb/api/database_spec.rb +32 -4
  29. data/spec/lib/influxdb/api/namespaces/{continuous_queries_spec.rb → continuous_queries/api_spec.rb} +2 -2
  30. data/spec/lib/influxdb/api/namespaces/continuous_queries/sql_spec.rb +41 -0
  31. data/spec/lib/influxdb/api/server_version_spec.rb +1 -0
  32. data/spec/spec_helper.rb +18 -0
  33. data/spec/support/version_resolver.rb +56 -0
  34. metadata +30 -5
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'users', version: '>0.7.3', integration: true do
4
+ let(:config){ Influxdb::Api::Configuration.new }
5
+ let(:client){ Influxdb::Api::Client.new(config) }
6
+
7
+ subject{ client.databases('db_name').users }
8
+
9
+ before do
10
+ client.databases.create('db_name')
11
+ subject.all.each{|u| subject.delete(u['name']) }
12
+ end
13
+
14
+ after{ client.databases.delete('db_name') }
15
+
16
+ describe '.all' do
17
+ context 'when there are no users' do
18
+ it 'returns empty array' do
19
+ expect(subject.all).to eq([])
20
+ end
21
+ end
22
+
23
+ context 'when there are some users' do
24
+ before do
25
+ subject.create(name: 'username1', password: 'mypass1')
26
+ subject.create(name: 'username2', password: 'mypass2')
27
+ end
28
+
29
+ it 'returns the list of users' do
30
+ expect(subject.all).to match_array([
31
+ { 'name' => 'username1', 'isAdmin' => false, 'writeTo' => '.*', 'readFrom' => '.*' },
32
+ { 'name' => 'username2', 'isAdmin' => false, 'writeTo' => '.*', 'readFrom' => '.*' }
33
+ ])
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '.create' do
39
+ it 'creates a new user with given name' do
40
+ expect{ subject.create(name: 'username', password: 'mypass') }.to change{ subject.all.size }.from(0).to(1)
41
+ end
42
+
43
+ context 'when there is user with the same name' do
44
+ before{ subject.create(name: 'username', password: 'mypass') }
45
+
46
+ it 'raises error' do
47
+ expect{ subject.create(name: 'username', password: 'mypass') }.to raise_error(
48
+ Influxdb::Api::Client::Errors::BadRequest, '[400] User username already exists'
49
+ )
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '.update' do
55
+ context 'when user does not exist' do
56
+ it 'raises error' do
57
+ expect{ subject.update('username', writeTo: 'log\..*', readFrom: '.*') }.to raise_error(
58
+ Influxdb::Api::Client::Errors::BadRequest, '[400] Invalid database name db_name'
59
+ )
60
+ end
61
+
62
+ context 'and did not pass both permissions' do
63
+ it 'does nothing' do
64
+ subject.update('username', writeTo: 'log\..*')
65
+ expect(subject.all).to eq([])
66
+ end
67
+ end
68
+ end
69
+
70
+ context 'when user exists' do
71
+ before{ subject.create(name: 'username', password: 'mypass') }
72
+
73
+ it 'updates user attributes' do
74
+ subject.update('username', writeTo: 'log\..*', readFrom: '.*')
75
+ expect(subject.all).to eq([
76
+ { 'name' => 'username', 'isAdmin' => false, 'writeTo' => 'log\..*', 'readFrom' => '.*' }
77
+ ])
78
+ end
79
+
80
+ context 'and did not pass both permissions' do
81
+ it 'does nothing' do
82
+ subject.update('username', writeTo: 'log\..*')
83
+ expect(subject.all).to eq([
84
+ { 'name' => 'username', 'isAdmin' => false, 'writeTo' => '.*', 'readFrom' => '.*' }
85
+ ])
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '.find' do
92
+ context 'when user does not exist' do
93
+ it 'returns nil' do
94
+ expect(subject.find('username2')).to be_nil
95
+ end
96
+ end
97
+
98
+ context 'when user exists' do
99
+ before{ subject.create(name: 'username', password: 'mypass') }
100
+
101
+ it 'returns user' do
102
+ expect(subject.find('username')).to eq(
103
+ 'name' => 'username', 'isAdmin' => false, 'writeTo' => '.*', 'readFrom' => '.*'
104
+ )
105
+ end
106
+ end
107
+ end
108
+
109
+ describe '.delete' do
110
+ context 'when user does not exist' do
111
+ it 'returns false' do
112
+ expect(subject.delete('username')).to be_falsy
113
+ end
114
+ end
115
+
116
+ context 'when user exists' do
117
+ before{ subject.create(name: 'username', password: 'mypass') }
118
+
119
+ it 'removes db and returns true' do
120
+ expect(subject.delete('username')).to be_truthy
121
+ end
122
+ end
123
+ end
124
+ end
@@ -19,14 +19,42 @@ describe Influxdb::Api::Namespaces do
19
19
  end
20
20
 
21
21
  describe '#continuous_queries' do
22
- specify{ expect(subject.continuous_queries).to be_instance_of(Influxdb::Api::Namespaces::ContinuousQueries) }
22
+ let(:version){ 'InfluxDB v0.8.3 (git: 023abcdef) (leveldb: 1.8)' }
23
+
24
+ before{ expect(client).to receive(:version).and_return(Influxdb::Api::ServerVersion.new(version)) }
25
+
26
+ specify{ expect(subject.continuous_queries).to be_instance_of(Influxdb::Api::Namespaces::ContinuousQueries::Api) }
23
27
  specify{ expect(subject.continuous_queries.client).to eq(client) }
24
28
  specify{ expect(subject.continuous_queries.database_name).to eq('dbname') }
29
+
30
+ context 'when Influxdb version is more than 0.8.3' do
31
+ let(:version){ 'InfluxDB v0.8.4 (git: 023abcdef) (leveldb: 1.8)' }
32
+
33
+ specify{ expect(subject.continuous_queries).to be_instance_of(Influxdb::Api::Namespaces::ContinuousQueries::Sql) }
34
+ specify{ expect(subject.continuous_queries.client).to eq(client) }
35
+ specify{ expect(subject.continuous_queries.database_name).to eq('dbname') }
36
+ end
25
37
  end
26
38
 
27
39
  describe '#shard_spaces' do
28
- specify{ expect(subject.shard_spaces).to be_instance_of(Influxdb::Api::Namespaces::ShardSpaces) }
29
- specify{ expect(subject.shard_spaces.client).to eq(client) }
30
- specify{ expect(subject.shard_spaces.database_name).to eq('dbname') }
40
+ before{ expect(client).to receive(:version).and_return(Influxdb::Api::ServerVersion.new(version)) }
41
+
42
+ context 'when Influxdb version is less than 0.8.3' do
43
+ let(:version){ 'InfluxDB v0.7.3 (git: 023abcdef) (leveldb: 1.8)' }
44
+
45
+ specify do
46
+ expect{ subject.shard_spaces }.to raise_error(
47
+ Influxdb::Api::UnsupportedFeature, "Shard space's API is supported only after 0.7.3 version. Current is 0.7.3"
48
+ )
49
+ end
50
+ end
51
+
52
+ context 'when Influxdb version is eaqual or more than 0.8.3' do
53
+ let(:version){ 'InfluxDB v0.8.3 (git: 023abcdef) (leveldb: 1.8)' }
54
+
55
+ specify{ expect(subject.shard_spaces).to be_instance_of(Influxdb::Api::Namespaces::ShardSpaces) }
56
+ specify{ expect(subject.shard_spaces.client).to eq(client) }
57
+ specify{ expect(subject.shard_spaces.database_name).to eq('dbname') }
58
+ end
31
59
  end
32
60
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Influxdb::Api::Namespaces::ContinuousQueries do
3
+ describe Influxdb::Api::Namespaces::ContinuousQueries::Api do
4
4
  let(:config){ Influxdb::Api::Configuration.new }
5
5
  let(:client){ Influxdb::Api::Client.new(config) }
6
6
 
7
- subject{ Influxdb::Api::Namespaces::ContinuousQueries.new(client, 'dbname') }
7
+ subject{ Influxdb::Api::Namespaces::ContinuousQueries::Api.new(client, 'dbname') }
8
8
 
9
9
  describe '#all' do
10
10
  before do
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Api::Namespaces::ContinuousQueries::Sql do
4
+ let(:config){ Influxdb::Api::Configuration.new }
5
+ let(:client){ Influxdb::Api::Client.new(config) }
6
+
7
+ subject{ Influxdb::Api::Namespaces::ContinuousQueries::Sql.new(client, 'dbname') }
8
+
9
+ describe '#all' do
10
+ let(:response){ MultiJson.dump([{
11
+ 'name' => 'continuous queries',
12
+ 'columns' => ['id', 'query'],
13
+ 'points' => [[1, 'select type from events into events.[page_id]']]
14
+ }]) }
15
+
16
+ before do
17
+ stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=LIST%20CONTINUOUS%20QUERIES').
18
+ to_return(status: 200, body: response, headers: { 'Content-Type' => 'application/json' })
19
+ end
20
+
21
+ specify{ expect(subject.all).to eq([{ 'id' => 1, 'query' => 'select type from events into events.[page_id]' }]) }
22
+ end
23
+
24
+ describe '#create' do
25
+ before do
26
+ stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=select%20type%20from%20events%20into%20events.[page_id]').
27
+ to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
28
+ end
29
+
30
+ specify{ expect(subject.create('select type from events into events.[page_id]')).to be_truthy }
31
+ end
32
+
33
+ describe '#delete' do
34
+ before do
35
+ stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=DROP%20CONTINUOUS%20QUERY%201').
36
+ to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
37
+ end
38
+
39
+ specify{ expect(subject.delete(1)).to be_truthy }
40
+ end
41
+ end
@@ -7,6 +7,7 @@ describe Influxdb::Api::ServerVersion do
7
7
 
8
8
  describe '#to_s' do
9
9
  specify{ expect(subject.to_s).to eq(source) }
10
+ specify{ expect(subject.to_s(:mini)).to eq('0.7.3') }
10
11
  end
11
12
 
12
13
  describe '#major' do
@@ -1,10 +1,28 @@
1
1
  require 'bundler'
2
2
  Bundler.require(:default, :test)
3
+ require 'support/version_resolver'
4
+
5
+ def allow_localhost
6
+ WebMock.disable_net_connect!(allow_localhost: true)
7
+ yield
8
+ ensure
9
+ WebMock.disable_net_connect!(allow_localhost: false)
10
+ end
11
+
12
+ version_resolver = allow_localhost{ VersionResolver.new }
13
+
14
+ puts "InfluxDB: #{version_resolver.server_version}"
3
15
 
4
16
  WebMock.disable_net_connect!(allow_localhost: false)
5
17
 
6
18
  RSpec.configure do |config|
7
19
  config.mock_with :rspec
20
+ config.filter_run_excluding version: ->(v){ !version_resolver.fit?(v) }
21
+ #config.filter_run_excluding((VERSIONS - [INFLUXDB_VERSION]).map{|v| { v => true } }.inject(&:merge))
22
+
23
+ config.around :each, integration: true do |example|
24
+ allow_localhost{ example.run }
25
+ end
8
26
 
9
27
  config.around :each, time_freeze: ->(v){ v.is_a?(Date) || v.is_a?(Time) || v.is_a?(String) } do |example|
10
28
  datetime = if example.metadata[:time_freeze].is_a?(String)
@@ -0,0 +1,56 @@
1
+ class VersionResolver
2
+ class Empty
3
+ def fit?(other)
4
+ false
5
+ end
6
+ end
7
+
8
+ class Version < Struct.new(:version, :op)
9
+ def fit?(other)
10
+ other.send(op || '==', version)
11
+ end
12
+ end
13
+
14
+ class Range < Struct.new(:version1, :version2)
15
+ def fit?(other)
16
+ other > version1 && other < version2
17
+ end
18
+ end
19
+
20
+ REGEXP = /([><=]{0,2})(\d+\.\d+\.\d+)/
21
+
22
+ attr_reader :server_version
23
+
24
+ def initialize(version = nil)
25
+ @server_version = build_version(version || get_server_version)
26
+ end
27
+
28
+ def fit?(tag)
29
+ tag = parse_tag(tag)
30
+ tag.fit?(server_version)
31
+ end
32
+
33
+ private
34
+
35
+ def build_version(v)
36
+ ::Gem::Version.new(v)
37
+ end
38
+
39
+ def get_server_version
40
+ Influxdb::Api.client.version.to_s(:mini)
41
+ end
42
+
43
+ def parse_tag(tag)
44
+ tags = tag.split(?-)
45
+
46
+ if tags.size > 1
47
+ Range.new(build_version(tags[0]), build_version(tags[1]))
48
+ else
49
+ if m = REGEXP.match(tags[0])
50
+ Version.new(build_version(m[2]), m[1].empty? ? nil : m[1])
51
+ else
52
+ Empty.new
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-api
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
  - undr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -95,6 +95,9 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - influxdb-api.gemspec
98
+ - influxdb/Dockerfile.0.7.3
99
+ - influxdb/Dockerfile.0.8.3
100
+ - influxdb/Dockerfile.0.8.8
98
101
  - lib/influxdb-api.rb
99
102
  - lib/influxdb.rb
100
103
  - lib/influxdb/api.rb
@@ -120,6 +123,15 @@ files:
120
123
  - lib/influxdb/api/namespaces/with_database.rb
121
124
  - lib/influxdb/api/server_version.rb
122
125
  - lib/influxdb/api/version.rb
126
+ - spec/intergrations/cluster_admins_spec.rb
127
+ - spec/intergrations/continuous_queries_spec.rb
128
+ - spec/intergrations/databases_spec.rb
129
+ - spec/intergrations/series_spec.rb
130
+ - spec/intergrations/servers_spec.rb
131
+ - spec/intergrations/shard_spaces_spec.rb
132
+ - spec/intergrations/shards_spec.rb
133
+ - spec/intergrations/users_0_7_3_spec.rb
134
+ - spec/intergrations/users_spec.rb
123
135
  - spec/lib/influxdb/api/client/connection_pool_spec.rb
124
136
  - spec/lib/influxdb/api/client/connection_spec.rb
125
137
  - spec/lib/influxdb/api/client/response_spec.rb
@@ -128,7 +140,8 @@ files:
128
140
  - spec/lib/influxdb/api/configuration_spec.rb
129
141
  - spec/lib/influxdb/api/database_spec.rb
130
142
  - spec/lib/influxdb/api/namespaces/cluster_admins_spec.rb
131
- - spec/lib/influxdb/api/namespaces/continuous_queries_spec.rb
143
+ - spec/lib/influxdb/api/namespaces/continuous_queries/api_spec.rb
144
+ - spec/lib/influxdb/api/namespaces/continuous_queries/sql_spec.rb
132
145
  - spec/lib/influxdb/api/namespaces/databases_spec.rb
133
146
  - spec/lib/influxdb/api/namespaces/series_spec.rb
134
147
  - spec/lib/influxdb/api/namespaces/servers_spec.rb
@@ -138,6 +151,7 @@ files:
138
151
  - spec/lib/influxdb/api/namespaces_spec.rb
139
152
  - spec/lib/influxdb/api/server_version_spec.rb
140
153
  - spec/spec_helper.rb
154
+ - spec/support/version_resolver.rb
141
155
  homepage: https://github.com/undr/influxdb-api
142
156
  licenses:
143
157
  - MIT
@@ -158,11 +172,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
172
  version: '0'
159
173
  requirements: []
160
174
  rubyforge_project:
161
- rubygems_version: 2.2.2
175
+ rubygems_version: 2.4.6
162
176
  signing_key:
163
177
  specification_version: 4
164
178
  summary: Ruby client for InfluxDB
165
179
  test_files:
180
+ - spec/intergrations/cluster_admins_spec.rb
181
+ - spec/intergrations/continuous_queries_spec.rb
182
+ - spec/intergrations/databases_spec.rb
183
+ - spec/intergrations/series_spec.rb
184
+ - spec/intergrations/servers_spec.rb
185
+ - spec/intergrations/shard_spaces_spec.rb
186
+ - spec/intergrations/shards_spec.rb
187
+ - spec/intergrations/users_0_7_3_spec.rb
188
+ - spec/intergrations/users_spec.rb
166
189
  - spec/lib/influxdb/api/client/connection_pool_spec.rb
167
190
  - spec/lib/influxdb/api/client/connection_spec.rb
168
191
  - spec/lib/influxdb/api/client/response_spec.rb
@@ -171,7 +194,8 @@ test_files:
171
194
  - spec/lib/influxdb/api/configuration_spec.rb
172
195
  - spec/lib/influxdb/api/database_spec.rb
173
196
  - spec/lib/influxdb/api/namespaces/cluster_admins_spec.rb
174
- - spec/lib/influxdb/api/namespaces/continuous_queries_spec.rb
197
+ - spec/lib/influxdb/api/namespaces/continuous_queries/api_spec.rb
198
+ - spec/lib/influxdb/api/namespaces/continuous_queries/sql_spec.rb
175
199
  - spec/lib/influxdb/api/namespaces/databases_spec.rb
176
200
  - spec/lib/influxdb/api/namespaces/series_spec.rb
177
201
  - spec/lib/influxdb/api/namespaces/servers_spec.rb
@@ -181,3 +205,4 @@ test_files:
181
205
  - spec/lib/influxdb/api/namespaces_spec.rb
182
206
  - spec/lib/influxdb/api/server_version_spec.rb
183
207
  - spec/spec_helper.rb
208
+ - spec/support/version_resolver.rb