thrift-validator 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thrift/validator.rb +6 -1
- data/lib/thrift/validator/version.rb +1 -1
- data/test/exceptions_test.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4e1c8126e551341a317cadd64f4808072bf943b
|
4
|
+
data.tar.gz: 477cce1e6c427a3a9464c95f2d00430baf236e24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4053c7fad656046a406d9d81681a106c30d53506abc9071a7fad2195dda4398fb92ce64aacafbe0a7b7c00675b86982e5575812d6f95e8e30cb8fe4e927cfe35
|
7
|
+
data.tar.gz: b776e8638590c4a59b297e9730d9bcc41f153f1741efa4919688d240998644347246929f8851cff8c4ef7d20dedf786f15d474af6f577b4d24b842ccfced5e8b
|
data/lib/thrift/validator.rb
CHANGED
@@ -4,7 +4,12 @@ require 'thrift'
|
|
4
4
|
module Thrift
|
5
5
|
class Validator
|
6
6
|
def validate(source)
|
7
|
-
|
7
|
+
begin
|
8
|
+
source.validate
|
9
|
+
rescue Thrift::ProtocolException => ex
|
10
|
+
message = "#{source.class.name}: #{ex}"
|
11
|
+
raise Thrift::ProtocolException.new(ex.type, message)
|
12
|
+
end
|
8
13
|
|
9
14
|
source.struct_fields.each_pair do |_, field|
|
10
15
|
type, name = field.fetch(:type), field.fetch(:name)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ExceptionsTest < MiniTest::Unit::TestCase
|
4
|
+
def test_exception_message_contains_class_name
|
5
|
+
# The error is in NestedExample - required_struct is unset
|
6
|
+
struct = NestedExample.new required_struct: nil
|
7
|
+
|
8
|
+
ex = assert_raises Thrift::ProtocolException do
|
9
|
+
Thrift::Validator.new.validate(struct)
|
10
|
+
end
|
11
|
+
assert_match /NestedExample/, ex.message
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_exception_message_contains_nested_class_name
|
15
|
+
# Here NestedExample is valid, but the error is one level down
|
16
|
+
# in SimpleStruct (its required_string is unset)
|
17
|
+
struct = NestedExample.new
|
18
|
+
struct.required_struct = SimpleStruct.new required_string: nil
|
19
|
+
|
20
|
+
ex = assert_raises Thrift::ProtocolException do
|
21
|
+
Thrift::Validator.new.validate(struct)
|
22
|
+
end
|
23
|
+
assert_match /SimpleStruct/, ex.message
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ahawkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thrift
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/thrift/validator/version.rb
|
71
71
|
- test.thrift
|
72
72
|
- test/acceptance_test.rb
|
73
|
+
- test/exceptions_test.rb
|
73
74
|
- test/test_helper.rb
|
74
75
|
- thrift-validator.gemspec
|
75
76
|
- vendor/gen-rb/test_constants.rb
|
@@ -100,4 +101,5 @@ specification_version: 4
|
|
100
101
|
summary: Recursive thrift struct validator
|
101
102
|
test_files:
|
102
103
|
- test/acceptance_test.rb
|
104
|
+
- test/exceptions_test.rb
|
103
105
|
- test/test_helper.rb
|