data_verifier 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/README.md +16 -2
- data/lib/data_verifier/inspector.rb +33 -0
- data/lib/data_verifier/version.rb +1 -1
- data/spec/lib/data_verifier/inspector_spec.rb +57 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d52c3237f5b600645684a31c7a46155b3a68ce637e3960f0669e6f81964a9dc1
|
4
|
+
data.tar.gz: 6556dfbb11b87981e03773e1d6c90bf0d02a20368c077bdd9ad651343ce8e150
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2d9030d8d567534247951428b010dbcadf94d1d5fc20a20c15f5648f0d10f362466ee58cebc3ecde73613552a4c7cb603256c211606b27ea275cc074de6da3
|
7
|
+
data.tar.gz: d26a3da3917f7ae7556a906729f17555fd7f6aa813b2946d58e6b4cfa33d363043f18876d3c8c1f76829109fad4b013af90edb6c8e4f14ee9da4e0162b86ea6b
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# data_verifier
|
2
2
|
|
3
|
+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/ajitsing/data_verifier/graphs/commit-activity)
|
4
|
+
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/MIT)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/data_verifier.svg)](https://badge.fury.io/rb/data_verifier)
|
6
|
+
[![HitCount](http://hits.dwyl.io/ajitsing/data_verifier.svg)](http://hits.dwyl.io/ajitsing/data_verifier)
|
7
|
+
![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/data_verifier?type=total)
|
8
|
+
[![Build Status](https://travis-ci.org/ajitsing/data_verifier.svg?branch=master)](https://travis-ci.org/ajitsing/data_verifier)
|
9
|
+
[![Twitter Follow](https://img.shields.io/twitter/follow/Ajit5ingh.svg?style=social)](https://twitter.com/Ajit5ingh)
|
10
|
+
|
3
11
|
There are times when we change the approach of modifying data and want to verify
|
4
12
|
that the data modified by the new approach is same as the old approach.
|
5
13
|
This gem is build for such verifications.
|
@@ -50,7 +58,10 @@ end
|
|
50
58
|
The below code will execute all the queries and store their result in json files.
|
51
59
|
|
52
60
|
```ruby
|
53
|
-
DataVerifier::BaselineBuilder.new
|
61
|
+
DataVerifier::BaselineBuilder.new
|
62
|
+
.with(db1_config)
|
63
|
+
.with(db2_config)
|
64
|
+
.build
|
54
65
|
```
|
55
66
|
|
56
67
|
#### Verification:
|
@@ -59,7 +70,10 @@ Below code will again execute the queries and will compare it with the baseline
|
|
59
70
|
After comparision it will create an excel file of the result.
|
60
71
|
|
61
72
|
```ruby
|
62
|
-
DataVerifier::Validator.new(
|
73
|
+
DataVerifier::Validator.new("data_sanity_report")
|
74
|
+
.validate_using(db1_config)
|
75
|
+
.validate_using(db2_config)
|
76
|
+
.generate_report
|
63
77
|
```
|
64
78
|
|
65
79
|
#### Result:
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DataVerifier
|
2
|
+
class Inspector
|
3
|
+
def initialize(configs, report_name:)
|
4
|
+
@configs = configs
|
5
|
+
@report_name = report_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def inspect(phase:)
|
9
|
+
if phase == :BUILD
|
10
|
+
puts "Running in :BUILD mode...\n"
|
11
|
+
build_baseline_data
|
12
|
+
elsif phase == :VERIFY
|
13
|
+
puts "Running in :VERIFY mode...\n"
|
14
|
+
validate_data
|
15
|
+
else
|
16
|
+
puts "Please pass a valid phase, valid values are :BUILD and :VERIFY\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def build_baseline_data
|
22
|
+
builder = DataVerifier::BaselineBuilder.new
|
23
|
+
@configs.each {|config| builder.with(config)}
|
24
|
+
builder.build
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_data
|
28
|
+
validator = DataVerifier::Validator.new(@report_name)
|
29
|
+
@configs.each {|config| validator.validate_using(config)}
|
30
|
+
validator.generate_report
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'data_verifier'
|
2
|
+
|
3
|
+
describe DataVerifier::Inspector do
|
4
|
+
describe '#inspect' do
|
5
|
+
let(:queries) {{
|
6
|
+
users_table: 'select * from users where id=100',
|
7
|
+
addresses_table: 'select * from addresses where user_id=100'
|
8
|
+
}}
|
9
|
+
|
10
|
+
let(:config1) {
|
11
|
+
DataVerifier::Config.new do |c|
|
12
|
+
c.data_identifier = '100'
|
13
|
+
c.queries = queries
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:config2) {
|
18
|
+
DataVerifier::Config.new do |c|
|
19
|
+
c.data_identifier = '100'
|
20
|
+
c.queries = queries
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
it 'should inspect in build mode' do
|
25
|
+
configs = [config1, config2]
|
26
|
+
inspector = DataVerifier::Inspector.new(configs, report_name: '100_data_sanity')
|
27
|
+
|
28
|
+
builder = instance_double(DataVerifier::BaselineBuilder)
|
29
|
+
expect(DataVerifier::BaselineBuilder).to receive(:new).and_return(builder)
|
30
|
+
|
31
|
+
expect(builder).to receive(:with).with(config1)
|
32
|
+
expect(builder).to receive(:with).with(config2)
|
33
|
+
expect(builder).to receive(:build)
|
34
|
+
|
35
|
+
inspector.inspect(phase: :BUILD)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should inspect in verify mode' do
|
39
|
+
configs = [config1, config2]
|
40
|
+
inspector = DataVerifier::Inspector.new(configs, report_name: '100_data_sanity')
|
41
|
+
|
42
|
+
validator = instance_double(DataVerifier::Validator)
|
43
|
+
expect(DataVerifier::Validator).to receive(:new).and_return(validator)
|
44
|
+
|
45
|
+
expect(validator).to receive(:validate_using).with(config1)
|
46
|
+
expect(validator).to receive(:validate_using).with(config2)
|
47
|
+
expect(validator).to receive(:generate_report)
|
48
|
+
|
49
|
+
inspector.inspect(phase: :VERIFY)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should do nothing when phase is invalid' do
|
53
|
+
inspector = DataVerifier::Inspector.new(nil, report_name: nil)
|
54
|
+
inspector.inspect(phase: :INVALID)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_verifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ajit Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|
@@ -73,6 +73,7 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- ".gitignore"
|
76
|
+
- ".travis.yml"
|
76
77
|
- Gemfile
|
77
78
|
- Gemfile.lock
|
78
79
|
- LICENSE
|
@@ -81,9 +82,11 @@ files:
|
|
81
82
|
- lib/data_verifier.rb
|
82
83
|
- lib/data_verifier/baseline_builder.rb
|
83
84
|
- lib/data_verifier/config.rb
|
85
|
+
- lib/data_verifier/inspector.rb
|
84
86
|
- lib/data_verifier/validator.rb
|
85
87
|
- lib/data_verifier/version.rb
|
86
88
|
- spec/lib/data_verifier/baseline_builder_spec.rb
|
89
|
+
- spec/lib/data_verifier/inspector_spec.rb
|
87
90
|
- spec/lib/data_verifier/validator_spec.rb
|
88
91
|
homepage: https://github.com/ajitsing/data_verifier
|
89
92
|
licenses:
|
@@ -111,4 +114,5 @@ specification_version: 4
|
|
111
114
|
summary: Generates an excel report to verify before and after state of db data
|
112
115
|
test_files:
|
113
116
|
- spec/lib/data_verifier/baseline_builder_spec.rb
|
117
|
+
- spec/lib/data_verifier/inspector_spec.rb
|
114
118
|
- spec/lib/data_verifier/validator_spec.rb
|