@@ -9,11 +9,7 @@ use crate::{
9
9
} ;
10
10
11
11
use mithril_client:: {
12
- common:: {
13
- AncillaryLocation , AncillaryLocationDiscriminants , DigestLocation ,
14
- DigestLocationDiscriminants , ImmutablesLocation , ImmutablesLocationDiscriminants ,
15
- MultiFilesUri ,
16
- } ,
12
+ common:: { AncillaryLocation , DigestLocation , ImmutablesLocation , MultiFilesUri } ,
17
13
MithrilResult ,
18
14
} ;
19
15
@@ -89,32 +85,19 @@ impl CardanoDbShowCommand {
89
85
] ,
90
86
] ;
91
87
92
- let mut digest_location_index = 1 ;
93
- for digest_location_type in [
94
- DigestLocationDiscriminants :: Aggregator ,
95
- DigestLocationDiscriminants :: CloudStorage ,
96
- ] {
97
- if let Some ( digest_location) = digest_location_row (
98
- digest_location_index,
99
- digest_location_type,
100
- & cardano_db_message. locations . digests ,
101
- ) {
102
- cardano_db_table. push ( digest_location) ;
103
- digest_location_index += 1 ;
104
- }
88
+ for digest_location in digest_location_rows ( & cardano_db_message. locations . digests ) {
89
+ cardano_db_table. push ( digest_location) ;
105
90
}
106
91
107
- if let Some ( immutables_location) = immutables_location_row (
108
- ImmutablesLocationDiscriminants :: CloudStorage ,
109
- & cardano_db_message. locations . immutables ,
110
- ) {
92
+ for immutables_location in
93
+ immutables_location_rows ( & cardano_db_message. locations . immutables )
94
+ {
111
95
cardano_db_table. push ( immutables_location) ;
112
96
}
113
97
114
- if let Some ( ancillary_location) = ancillary_location_row (
115
- AncillaryLocationDiscriminants :: CloudStorage ,
116
- & cardano_db_message. locations . ancillary ,
117
- ) {
98
+ for ancillary_location in
99
+ ancillary_location_rows ( & cardano_db_message. locations . ancillary )
100
+ {
118
101
cardano_db_table. push ( ancillary_location) ;
119
102
}
120
103
@@ -134,97 +117,63 @@ impl CardanoDbShowCommand {
134
117
}
135
118
}
136
119
137
- fn digest_location_row (
138
- index : usize ,
139
- location_type : DigestLocationDiscriminants ,
140
- locations : & [ DigestLocation ] ,
141
- ) -> Option < Vec < CellStruct > > {
142
- let uris = locations
120
+ fn digest_location_rows ( locations : & [ DigestLocation ] ) -> Vec < Vec < CellStruct > > {
121
+ let archive_type_location = "Digest location" ;
122
+
123
+ locations
143
124
. iter ( )
144
- . filter_map ( |location| match ( location, location_type) {
145
- ( DigestLocation :: Aggregator { uri } , DigestLocationDiscriminants :: Aggregator ) => {
146
- Some ( format ! ( "uri: \" {}\" " , uri) )
125
+ . enumerate ( )
126
+ . map ( |( index, location) | match location {
127
+ DigestLocation :: Aggregator { uri } => {
128
+ vec ! [
129
+ format!( "{archive_type_location} ({})" , index + 1 ) . cell( ) ,
130
+ format!( "Aggregator, uri: \" {}\" " , uri) . cell( ) ,
131
+ ]
147
132
}
148
- ( DigestLocation :: CloudStorage { uri } , DigestLocationDiscriminants :: CloudStorage ) => {
149
- Some ( format ! ( "uri: \" {}\" " , uri) )
133
+ DigestLocation :: CloudStorage { uri } => {
134
+ vec ! [
135
+ format!( "{archive_type_location} ({})" , index + 1 ) . cell( ) ,
136
+ format!( "CloudStorage, uri: \" {}\" " , uri) . cell( ) ,
137
+ ]
150
138
}
151
- _ => None ,
152
139
} )
153
- . collect :: < Vec < String > > ( )
154
- . join ( "," ) ;
155
-
156
- if uris. is_empty ( ) {
157
- None
158
- } else {
159
- Some ( vec ! [
160
- format!( "Digest location ({index})" ) . cell( ) ,
161
- format!( "{location_type:?}, {uris}" ) . cell( ) ,
162
- ] )
163
- }
140
+ . collect ( )
164
141
}
165
142
166
- fn immutables_location_row (
167
- location_type : ImmutablesLocationDiscriminants ,
168
- locations : & [ ImmutablesLocation ] ,
169
- ) -> Option < Vec < CellStruct > > {
170
- let uris = locations
143
+ fn immutables_location_rows ( locations : & [ ImmutablesLocation ] ) -> Vec < Vec < CellStruct > > {
144
+ let archive_type_location = "Immutables location" ;
145
+
146
+ locations
171
147
. iter ( )
172
- . map ( |location| match ( location, location_type) {
173
- (
174
- ImmutablesLocation :: CloudStorage { uri } ,
175
- ImmutablesLocationDiscriminants :: CloudStorage ,
176
- ) => match uri {
148
+ . enumerate ( )
149
+ . map ( |( index, location) | match location {
150
+ ImmutablesLocation :: CloudStorage { uri } => match uri {
177
151
MultiFilesUri :: Template ( template_uri) => {
178
- format ! ( "template_uri: \" {}\" " , template_uri. 0 )
152
+ vec ! [
153
+ format!( "{archive_type_location} ({})" , index + 1 ) . cell( ) ,
154
+ format!( "CloudStorage, template_uri: \" {}\" " , template_uri. 0 ) . cell( ) ,
155
+ ]
179
156
}
180
157
} ,
181
158
} )
182
- . collect :: < Vec < String > > ( )
183
- . join ( "," ) ;
184
-
185
- if uris. is_empty ( ) {
186
- None
187
- } else {
188
- Some ( vec ! [
189
- "Immutables location" . to_string( ) . cell( ) ,
190
- format!(
191
- "{:?}, {}" ,
192
- ImmutablesLocationDiscriminants :: CloudStorage ,
193
- uris
194
- )
195
- . cell( ) ,
196
- ] )
197
- }
159
+ . collect ( )
198
160
}
199
161
200
- fn ancillary_location_row (
201
- location_type : AncillaryLocationDiscriminants ,
202
- locations : & [ AncillaryLocation ] ,
203
- ) -> Option < Vec < CellStruct > > {
204
- let uris = locations
162
+ fn ancillary_location_rows ( locations : & [ AncillaryLocation ] ) -> Vec < Vec < CellStruct > > {
163
+ let archive_type_location = "Ancillary location" ;
164
+
165
+ locations
205
166
. iter ( )
206
- . map ( |location| match ( location, location_type) {
207
- (
208
- AncillaryLocation :: CloudStorage { uri } ,
209
- AncillaryLocationDiscriminants :: CloudStorage ,
210
- ) => format ! ( "uri: \" {}\" " , uri) ,
167
+ . enumerate ( )
168
+ . map ( |( index, location) | match location {
169
+ AncillaryLocation :: CloudStorage { uri } => {
170
+ vec ! [
171
+ format!( "{archive_type_location} ({})" , index + 1 ) . cell( ) ,
172
+ format!( "CloudStorage, uri: \" {}\" " , uri) . cell( ) ,
173
+ ]
174
+ }
211
175
} )
212
- . collect :: < Vec < String > > ( )
213
- . join ( "," ) ;
214
-
215
- if uris. is_empty ( ) {
216
- None
217
- } else {
218
- Some ( vec ! [
219
- "Ancillary location" . to_string( ) . cell( ) ,
220
- format!(
221
- "{:?}, {}" ,
222
- AncillaryLocationDiscriminants :: CloudStorage ,
223
- uris
224
- )
225
- . cell( ) ,
226
- ] )
227
- }
176
+ . collect ( )
228
177
}
229
178
230
179
#[ cfg( test) ]
@@ -234,18 +183,14 @@ mod tests {
234
183
use super :: * ;
235
184
236
185
#[ test]
237
- fn digest_location_row_returns_none_when_no_uri_found_for_location_type ( ) {
238
- let locations = vec ! [ DigestLocation :: Aggregator {
239
- uri: "http://aggregator.net/" . to_string( ) ,
240
- } ] ;
241
-
242
- let row = digest_location_row ( 123 , DigestLocationDiscriminants :: CloudStorage , & locations) ;
186
+ fn digest_location_rows_when_no_uri_found ( ) {
187
+ let rows = digest_location_rows ( & [ ] ) ;
243
188
244
- assert ! ( row . is_none ( ) ) ;
189
+ assert ! ( rows . is_empty ( ) ) ;
245
190
}
246
191
247
192
#[ test]
248
- fn digest_location_row_returns_some_when_uri_found_for_location_type ( ) {
193
+ fn digest_location_rows_when_uris_found ( ) {
249
194
let locations = vec ! [
250
195
DigestLocation :: Aggregator {
251
196
uri: "http://aggregator.net/" . to_string( ) ,
@@ -255,47 +200,77 @@ mod tests {
255
200
} ,
256
201
] ;
257
202
258
- let row = digest_location_row ( 123 , DigestLocationDiscriminants :: CloudStorage , & locations) ;
259
- assert ! ( row . is_some ( ) ) ;
203
+ let rows = digest_location_rows ( & locations) ;
204
+ assert ! ( rows . len ( ) == 2 ) ;
260
205
261
- let row = digest_location_row ( 456 , DigestLocationDiscriminants :: Aggregator , & locations) ;
262
- assert ! ( row. is_some( ) ) ;
206
+ let table = rows. table ( ) ;
207
+ let rows_rendered = table. display ( ) . unwrap ( ) . to_string ( ) ;
208
+
209
+ assert ! ( rows_rendered. contains( "Digest location (1)" ) ) ;
210
+ assert ! ( rows_rendered. contains( "CloudStorage, uri: \" http://cloudstorage.com/\" " ) ) ;
211
+ assert ! ( rows_rendered. contains( "Digest location (2)" ) ) ;
212
+ assert ! ( rows_rendered. contains( "Aggregator, uri: \" http://aggregator.net/\" " ) ) ;
263
213
}
264
214
265
215
#[ test]
266
- fn immutables_location_row_returns_none_when_no_uri_found_for_location_type ( ) {
267
- let row = immutables_location_row ( ImmutablesLocationDiscriminants :: CloudStorage , & [ ] ) ;
216
+ fn immutables_location_rows_when_no_uri_found ( ) {
217
+ let rows = immutables_location_rows ( & [ ] ) ;
268
218
269
- assert ! ( row . is_none ( ) ) ;
219
+ assert ! ( rows . is_empty ( ) ) ;
270
220
}
271
221
272
222
#[ test]
273
- fn immutables_location_row_returns_some_when_uri_found_for_location_type ( ) {
274
- let locations = vec ! [ ImmutablesLocation :: CloudStorage {
275
- uri: MultiFilesUri :: Template ( TemplateUri ( "http://cloudstorage.com/" . to_string( ) ) ) ,
276
- } ] ;
223
+ fn immutables_location_row_returns_some_when_uri_found ( ) {
224
+ let locations = vec ! [
225
+ ImmutablesLocation :: CloudStorage {
226
+ uri: MultiFilesUri :: Template ( TemplateUri ( "http://cloudstorage1.com/" . to_string( ) ) ) ,
227
+ } ,
228
+ ImmutablesLocation :: CloudStorage {
229
+ uri: MultiFilesUri :: Template ( TemplateUri ( "http://cloudstorage2.com/" . to_string( ) ) ) ,
230
+ } ,
231
+ ] ;
232
+
233
+ let rows = immutables_location_rows ( & locations) ;
234
+
235
+ assert ! ( rows. len( ) == 2 ) ;
277
236
278
- let row =
279
- immutables_location_row ( ImmutablesLocationDiscriminants :: CloudStorage , & locations ) ;
237
+ let table = rows . table ( ) ;
238
+ let rows_rendered = table . display ( ) . unwrap ( ) . to_string ( ) ;
280
239
281
- assert ! ( row. is_some( ) ) ;
240
+ assert ! ( rows_rendered. contains( "Immutables location (1)" ) ) ;
241
+ assert ! ( rows_rendered. contains( "CloudStorage, template_uri: \" http://cloudstorage1.com/\" " ) ) ;
242
+ assert ! ( rows_rendered. contains( "Immutables location (2)" ) ) ;
243
+ assert ! ( rows_rendered. contains( "CloudStorage, template_uri: \" http://cloudstorage2.com/\" " ) ) ;
282
244
}
283
245
284
246
#[ test]
285
- fn ancillary_location_row_returns_none_when_no_uri_found_for_location_type ( ) {
286
- let row = ancillary_location_row ( AncillaryLocationDiscriminants :: CloudStorage , & [ ] ) ;
247
+ fn ancillary_location_rows_when_no_uri_found ( ) {
248
+ let rows = ancillary_location_rows ( & [ ] ) ;
287
249
288
- assert ! ( row . is_none ( ) ) ;
250
+ assert ! ( rows . is_empty ( ) ) ;
289
251
}
290
252
291
253
#[ test]
292
- fn ancillary_location_row_returns_some_when_uri_found_for_location_type ( ) {
293
- let locations = vec ! [ AncillaryLocation :: CloudStorage {
294
- uri: "http://cloudstorage.com/" . to_string( ) ,
295
- } ] ;
254
+ fn ancillary_location_rows_when_uris_found ( ) {
255
+ let locations = vec ! [
256
+ AncillaryLocation :: CloudStorage {
257
+ uri: "http://cloudstorage1.com/" . to_string( ) ,
258
+ } ,
259
+ AncillaryLocation :: CloudStorage {
260
+ uri: "http://cloudstorage2.com/" . to_string( ) ,
261
+ } ,
262
+ ] ;
263
+
264
+ let rows = ancillary_location_rows ( & locations) ;
265
+
266
+ assert ! ( rows. len( ) == 2 ) ;
296
267
297
- let row = ancillary_location_row ( AncillaryLocationDiscriminants :: CloudStorage , & locations) ;
268
+ let table = rows. table ( ) ;
269
+ let rows_rendered = table. display ( ) . unwrap ( ) . to_string ( ) ;
298
270
299
- assert ! ( row. is_some( ) ) ;
271
+ assert ! ( rows_rendered. contains( "Ancillary location (1)" ) ) ;
272
+ assert ! ( rows_rendered. contains( "CloudStorage, uri: \" http://cloudstorage1.com/\" " ) ) ;
273
+ assert ! ( rows_rendered. contains( "Ancillary location (2)" ) ) ;
274
+ assert ! ( rows_rendered. contains( "CloudStorage, uri: \" http://cloudstorage2.com/\" " ) ) ;
300
275
}
301
276
}
0 commit comments