Skip to content

Commit

Permalink
multicloud: huawei: rework responses_test
Browse files Browse the repository at this point in the history
 - use json object Equals method for comparison
 - t.Fatalf on unexpected errors
  • Loading branch information
yousong committed Jun 15, 2020
1 parent 2a32627 commit 0208314
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/multicloud/huawei/client/responses/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package responses

import (
"fmt"
"testing"

"yunion.io/x/jsonutils"
Expand All @@ -25,14 +24,14 @@ func TestTransColonToDot(t *testing.T) {
raw := `{"A:b::C": "1:2:3", "A": true, "B": ["1:2", ":", "c"], "D:E": true}`
obj, err := jsonutils.ParseString(raw)
if err != nil {
fmt.Println(err)
t.Fatalf("json parse: %v", err)
}
nobj, err := TransColonToDot(obj)
gotj, err := TransColonToDot(obj)
if err != nil {
fmt.Println(err)
t.Fatalf("trans: %v", err)
}

if nobj.String() != `{"A":true,"A.b..C":"1:2:3","B":["1:2",":","c"],"D.E":true}` {
t.Errorf("trans failed")
wantj, _ := jsonutils.ParseString(`{"A":true,"A.b..C":"1:2:3","B":["1:2",":","c"],"D.E":true}`)
if !wantj.Equals(gotj) {
t.Errorf("trans failed, want:\n%s\ngot:\n%s", wantj, gotj)
}
}

0 comments on commit 0208314

Please sign in to comment.