@@ -15,11 +15,17 @@ func TestValidator_Validate(t *testing.T) {
1515 name string
1616 filename string
1717 want * Results
18+
19+ lighterChanIDValidation bool
1820 }{
1921 {name : "Valid data" , filename : "valid-data.json" , want : & Results {
2022 Stats : map [string ]int {"channels" : 3 , "devices" : 2 , "members" : 4 , "messages" : 3 , "reactions" : 3 , "users" : 4 },
2123 Errors : nil ,
2224 }},
25+ {name : "Valid channels with lighter channel ID validation" , filename : "valid-channels-with-light.json" , lighterChanIDValidation : true , want : & Results {
26+ Stats : map [string ]int {"channels" : 2 , "devices" : 0 , "members" : 2 , "messages" : 1 , "reactions" : 0 , "users" : 2 },
27+ Errors : nil ,
28+ }},
2329 {name : "Invalid users" , filename : "invalid-users.json" , want : & Results {
2430 Stats : map [string ]int {"channels" : 0 , "devices" : 0 , "members" : 0 , "messages" : 0 , "reactions" : 0 , "users" : 1 },
2531 Errors : []error {
@@ -38,7 +44,7 @@ func TestValidator_Validate(t *testing.T) {
3844 errors .New (`validation error: either channel.id or channel.member_ids required` ),
3945 errors .New (`validation error: channel.id max length exceeded (64)` ),
4046 errors .New (`validation error: channel.type required` ),
41- errors .New (`validation error: channel.id invalid ("^[\w-]*$" allowed)` ),
47+ errors .New (`validation error: channel.id "channelA@abc" invalid ("^[\w-]*$" allowed)` ),
4248 errors .New (`validation error: channel.created_by required` ),
4349 errors .New (`validation error: channel.cid is a reserved field` ),
4450 errors .New (`reference error: channel.type "" doesn't exist (channel ":channelA")` ),
@@ -108,12 +114,16 @@ func TestValidator_Validate(t *testing.T) {
108114 require .NoError (t , err )
109115 defer f .Close ()
110116
111- v := New (f , []* stream.Role {{Name : "user" }}, map [string ]* stream.ChannelType {"messaging" : nil })
117+ var options []Options
118+ if tt .lighterChanIDValidation {
119+ options = append (options , LighterValidationChannelID ())
120+ }
121+ v := New (f , []* stream.Role {{Name : "user" }}, map [string ]* stream.ChannelType {"messaging" : nil }, options ... )
112122
113123 got := v .Validate ()
114124
115125 require .Equal (t , tt .want .Stats , got .Stats )
116- require .Equal (t , len (tt .want .Errors ), len (got .Errors ))
126+ require .Equal (t , len (tt .want .Errors ), len (got .Errors ), got . Errors )
117127 for i := range tt .want .Errors {
118128 require .Equal (t , tt .want .Errors [i ].Error (), got .Errors [i ].Error (), fmt .Sprintf (`errors #%d doesn't match` , i ))
119129 }
0 commit comments