mirror of
https://github.com/jech/galene.git
synced 2024-11-24 17:45:58 +01:00
Add test for parseStatefulToken.
This commit is contained in:
parent
76066a1a10
commit
dc8a78be32
1 changed files with 52 additions and 0 deletions
52
rtpconn/webclient_test.go
Normal file
52
rtpconn/webclient_test.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package rtpconn
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jech/galene/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tokens = []string{
|
||||||
|
`{
|
||||||
|
"token": "a",
|
||||||
|
"group": "g",
|
||||||
|
"username": "u",
|
||||||
|
"permissions":["present"],
|
||||||
|
"expires": "2023-05-03T20:24:47.616624532+02:00"
|
||||||
|
}`,
|
||||||
|
`{
|
||||||
|
"token": "a",
|
||||||
|
"group": "g"
|
||||||
|
}`,
|
||||||
|
`{
|
||||||
|
"token": "a",
|
||||||
|
"group": "g",
|
||||||
|
"username":""
|
||||||
|
}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseStatefulToken(t *testing.T) {
|
||||||
|
for i, tok := range tokens {
|
||||||
|
var t1 *token.Stateful
|
||||||
|
err := json.Unmarshal([]byte(tok), &t1)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unmarshal %v: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var m map[string]interface{}
|
||||||
|
err = json.Unmarshal([]byte(tok), &m)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unmarshal (map) %v: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t2, err := parseStatefulToken(m)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("parseStatefulToken %v: %v", i, err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(t1, t2) {
|
||||||
|
t.Errorf("Mismatch: %v, %v", t1, t2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue