dtmcli 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/dtmcli.gemspec +1 -1
- data/lib/dtmcli.rb +1 -0
- data/lib/dtmcli/msg.rb +45 -0
- data/lib/dtmcli/version.rb +1 -1
- data/test/test_msg.rb +226 -0
- data/test/test_saga.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c178227ab5797145c53527f60aa649f84d00f7cd726b4f67bfd2d934dfaa1e9
|
4
|
+
data.tar.gz: c79e08a3c9c27c7352455205f1cb7acde4094ecb05c9a23b57a6de89ed455346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17c7cc58cd05aeda876fe42dccfafe257465980e271ab14126912e0aa93a0f83211556d6f03476e0c88c009b297727a779c5dbd5b5c6a465cb99ab42522fc6ef
|
7
|
+
data.tar.gz: 83a7eb7c53d24c5e3074aa49f329633999982da0a1d8880971cf9a79b47dd5b3148d225a7cdaf1e00b142b48d36edbcc5c77fb8e1625fb9a4ebcad3baf8badcb
|
data/README.md
CHANGED
@@ -37,4 +37,16 @@ saga.add(biz_url + '/TransOut', biz_url + '/TransOutRevert', post_data)
|
|
37
37
|
saga.add(biz_url + '/TransIn', biz_url + '/TransInRevert', post_data)
|
38
38
|
|
39
39
|
saga.submit
|
40
|
+
|
41
|
+
# Model Transcation Msg
|
42
|
+
dtm_msg = Dtmcli::Msg.new(dtm_url)
|
43
|
+
dtm_msg.gen_gid
|
44
|
+
|
45
|
+
post_data = {amount: 30}
|
46
|
+
dtm_msg.add(biz_url + '/TransOut', post_data)
|
47
|
+
dtm_msg.add(biz_url + '/TransIn', post_data)
|
48
|
+
|
49
|
+
dtm_msg.prepare(biz_url + '/TransQuery')
|
50
|
+
|
51
|
+
dtm_msg.submit
|
40
52
|
```
|
data/dtmcli.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'faraday', '~> 1.6.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", '
|
23
|
+
spec.add_development_dependency "bundler", '~> 2.2'
|
24
24
|
spec.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.4'
|
25
25
|
spec.add_development_dependency 'webmock', '~> 3.13.0'
|
26
26
|
|
data/lib/dtmcli.rb
CHANGED
data/lib/dtmcli/msg.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Dtmcli
|
2
|
+
class Msg
|
3
|
+
attr_accessor :gid, :steps, :query_prepared
|
4
|
+
attr_reader :dtm, :dtm_url
|
5
|
+
|
6
|
+
TRANS_TYPE = 'msg'
|
7
|
+
|
8
|
+
def initialize(dtm_url)
|
9
|
+
@dtm_url = dtm_url
|
10
|
+
@dtm = Dtm.new(dtm_url)
|
11
|
+
@steps = []
|
12
|
+
@query_prepared = ''
|
13
|
+
end
|
14
|
+
|
15
|
+
def gen_gid
|
16
|
+
@gid = IdGenerator.gen_gid(dtm_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(action, post_data)
|
20
|
+
step = {
|
21
|
+
action: action,
|
22
|
+
data: post_data.to_json,
|
23
|
+
}
|
24
|
+
@steps << step
|
25
|
+
end
|
26
|
+
|
27
|
+
def prepare(p_url)
|
28
|
+
@query_prepared = p_url if !p_url.nil?
|
29
|
+
dtm.prepare(wrap_tbody)
|
30
|
+
end
|
31
|
+
|
32
|
+
def submit
|
33
|
+
dtm.submit(wrap_tbody)
|
34
|
+
end
|
35
|
+
|
36
|
+
def wrap_tbody
|
37
|
+
{
|
38
|
+
gid: gid,
|
39
|
+
trans_type: TRANS_TYPE,
|
40
|
+
steps: steps,
|
41
|
+
query_prepared: query_prepared
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/dtmcli/version.rb
CHANGED
data/test/test_msg.rb
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMsg < Minitest::Test
|
4
|
+
def setup
|
5
|
+
mocking!
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_initialize
|
9
|
+
saga = Dtmcli::Msg.new('dtmurl')
|
10
|
+
assert_equal 'dtmurl', saga.dtm_url
|
11
|
+
assert_equal [], saga.steps
|
12
|
+
assert_equal '', saga.query_prepared
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_gen_gid_succ
|
16
|
+
stub_request(:get, @dtm_url + "/newGid").
|
17
|
+
with(headers: @headers).
|
18
|
+
to_return(
|
19
|
+
status: 200,
|
20
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
21
|
+
headers: {}
|
22
|
+
)
|
23
|
+
|
24
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
25
|
+
dtm_msg.gen_gid
|
26
|
+
assert_equal 'test_gid', dtm_msg.gid
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_gen_gid_fail
|
30
|
+
stub_request(:get, @dtm_url + "/newGid").
|
31
|
+
with(headers: @headers).
|
32
|
+
to_return(status: 200, body: {dtm_result: 'FAILURE', gid: ''}.to_json)
|
33
|
+
|
34
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
35
|
+
assert_raises(Dtmcli::DtmSvrError) {
|
36
|
+
dtm_msg.gen_gid
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_add_succ
|
41
|
+
stub_request(:get, @dtm_url + "/newGid").
|
42
|
+
with(headers: @headers).
|
43
|
+
to_return(
|
44
|
+
status: 200,
|
45
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
46
|
+
headers: {}
|
47
|
+
)
|
48
|
+
|
49
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
50
|
+
assert_equal [], dtm_msg.steps
|
51
|
+
dtm_msg.gen_gid
|
52
|
+
|
53
|
+
post_data = {amount: 30}
|
54
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
55
|
+
assert_equal 1, dtm_msg.steps.size
|
56
|
+
step1 = dtm_msg.steps[0]
|
57
|
+
assert_equal @host + '/TransOut1', step1[:action]
|
58
|
+
|
59
|
+
dtm_msg.add(@host + '/TransOut2', post_data)
|
60
|
+
assert_equal 2, dtm_msg.steps.size
|
61
|
+
step2 = dtm_msg.steps[1]
|
62
|
+
assert_equal @host + '/TransOut2', step2[:action]
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_prepare_succ
|
66
|
+
stub_request(:get, @dtm_url + "/newGid").
|
67
|
+
with(headers: @headers).
|
68
|
+
to_return(
|
69
|
+
status: 200,
|
70
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
71
|
+
headers: {}
|
72
|
+
)
|
73
|
+
|
74
|
+
stub_request(:post, @dtm_url + "/prepare").
|
75
|
+
with(headers: @headers).
|
76
|
+
to_return(
|
77
|
+
status: 200,
|
78
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
79
|
+
)
|
80
|
+
|
81
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
82
|
+
assert_equal [], dtm_msg.steps
|
83
|
+
dtm_msg.gen_gid
|
84
|
+
|
85
|
+
post_data = {amount: 30}
|
86
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
87
|
+
|
88
|
+
dtm_msg.prepare(@host + '/TransQuery')
|
89
|
+
assert_equal @host + '/TransQuery', dtm_msg.query_prepared
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_prepare_fail
|
93
|
+
stub_request(:get, @dtm_url + "/newGid").
|
94
|
+
with(headers: @headers).
|
95
|
+
to_return(
|
96
|
+
status: 200,
|
97
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
98
|
+
headers: {}
|
99
|
+
)
|
100
|
+
|
101
|
+
stub_request(:post, @dtm_url + "/prepare").
|
102
|
+
with(headers: @headers).
|
103
|
+
to_return(
|
104
|
+
status: 200,
|
105
|
+
body: {dtm_result: 'FAILURE', gid: ''}.to_json,
|
106
|
+
)
|
107
|
+
|
108
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
109
|
+
assert_equal [], dtm_msg.steps
|
110
|
+
dtm_msg.gen_gid
|
111
|
+
|
112
|
+
post_data = {amount: 30}
|
113
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
114
|
+
|
115
|
+
assert_raises(Dtmcli::DtmSvrError) {
|
116
|
+
dtm_msg.prepare(@host + '/TransQuery')
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_wrap_tbody
|
121
|
+
stub_request(:get, @dtm_url + "/newGid").
|
122
|
+
with(headers: @headers).
|
123
|
+
to_return(
|
124
|
+
status: 200,
|
125
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
126
|
+
headers: {}
|
127
|
+
)
|
128
|
+
|
129
|
+
stub_request(:post, @dtm_url + "/prepare").
|
130
|
+
with(headers: @headers).
|
131
|
+
to_return(
|
132
|
+
status: 200,
|
133
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
134
|
+
)
|
135
|
+
|
136
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
137
|
+
assert_equal [], dtm_msg.steps
|
138
|
+
dtm_msg.gen_gid
|
139
|
+
|
140
|
+
post_data = {amount: 30}
|
141
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
142
|
+
|
143
|
+
dtm_msg.prepare(@host + '/TransQuery')
|
144
|
+
|
145
|
+
tbody = dtm_msg.wrap_tbody
|
146
|
+
assert_equal 'test_gid', tbody[:gid]
|
147
|
+
assert_equal 'msg', tbody[:trans_type]
|
148
|
+
assert_equal 1, tbody[:steps].size
|
149
|
+
assert_equal @host + '/TransQuery', tbody[:query_prepared]
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_submit_succ
|
153
|
+
stub_request(:get, @dtm_url + "/newGid").
|
154
|
+
with(headers: @headers).
|
155
|
+
to_return(
|
156
|
+
status: 200,
|
157
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
158
|
+
headers: {}
|
159
|
+
)
|
160
|
+
|
161
|
+
stub_request(:post, @dtm_url + "/prepare").
|
162
|
+
with(headers: @headers).
|
163
|
+
to_return(
|
164
|
+
status: 200,
|
165
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
166
|
+
)
|
167
|
+
|
168
|
+
stub_request(:post, @dtm_url + "/submit").
|
169
|
+
with(headers: @headers).
|
170
|
+
to_return(
|
171
|
+
status: 200,
|
172
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
173
|
+
)
|
174
|
+
|
175
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
176
|
+
assert_equal [], dtm_msg.steps
|
177
|
+
dtm_msg.gen_gid
|
178
|
+
|
179
|
+
post_data = {amount: 30}
|
180
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
181
|
+
|
182
|
+
dtm_msg.prepare(@host + '/TransQuery')
|
183
|
+
assert_equal @host + '/TransQuery', dtm_msg.query_prepared
|
184
|
+
|
185
|
+
res = dtm_msg.submit
|
186
|
+
assert_equal 'SUCCESS', res['dtm_result']
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_submit_succ
|
190
|
+
stub_request(:get, @dtm_url + "/newGid").
|
191
|
+
with(headers: @headers).
|
192
|
+
to_return(
|
193
|
+
status: 200,
|
194
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
195
|
+
headers: {}
|
196
|
+
)
|
197
|
+
|
198
|
+
stub_request(:post, @dtm_url + "/prepare").
|
199
|
+
with(headers: @headers).
|
200
|
+
to_return(
|
201
|
+
status: 200,
|
202
|
+
body: {dtm_result: 'SUCCESS', gid: 'test_gid'}.to_json,
|
203
|
+
)
|
204
|
+
|
205
|
+
stub_request(:post, @dtm_url + "/submit").
|
206
|
+
with(headers: @headers).
|
207
|
+
to_return(
|
208
|
+
status: 200,
|
209
|
+
body: {dtm_result: 'FAILURE', gid: ''}.to_json,
|
210
|
+
)
|
211
|
+
|
212
|
+
dtm_msg = Dtmcli::Msg.new(@dtm_url)
|
213
|
+
assert_equal [], dtm_msg.steps
|
214
|
+
dtm_msg.gen_gid
|
215
|
+
|
216
|
+
post_data = {amount: 30}
|
217
|
+
dtm_msg.add(@host + '/TransOut1', post_data)
|
218
|
+
|
219
|
+
dtm_msg.prepare(@host + '/TransQuery')
|
220
|
+
assert_equal @host + '/TransQuery', dtm_msg.query_prepared
|
221
|
+
|
222
|
+
assert_raises(Dtmcli::DtmSvrError) {
|
223
|
+
dtm_msg.submit
|
224
|
+
}
|
225
|
+
end
|
226
|
+
end
|
data/test/test_saga.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtmcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jedhu0
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.2
|
33
|
+
version: '2.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.2
|
40
|
+
version: '2.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,12 +88,14 @@ files:
|
|
88
88
|
- lib/dtmcli/dtm.rb
|
89
89
|
- lib/dtmcli/errors.rb
|
90
90
|
- lib/dtmcli/id_generator.rb
|
91
|
+
- lib/dtmcli/msg.rb
|
91
92
|
- lib/dtmcli/proxy.rb
|
92
93
|
- lib/dtmcli/saga.rb
|
93
94
|
- lib/dtmcli/tcc.rb
|
94
95
|
- lib/dtmcli/version.rb
|
95
96
|
- test/helper.rb
|
96
97
|
- test/test_id_generator.rb
|
98
|
+
- test/test_msg.rb
|
97
99
|
- test/test_saga.rb
|
98
100
|
- test/test_tcc.rb
|
99
101
|
homepage: https://github.com/jedhu0/dtmcli
|
@@ -122,5 +124,6 @@ summary: client for dtm
|
|
122
124
|
test_files:
|
123
125
|
- test/helper.rb
|
124
126
|
- test/test_id_generator.rb
|
127
|
+
- test/test_msg.rb
|
125
128
|
- test/test_saga.rb
|
126
129
|
- test/test_tcc.rb
|