|
6 | 6 |
|
7 | 7 | "github.com/gomodule/redigo/redis"
|
8 | 8 | "github.com/stretchr/testify/assert"
|
| 9 | + "encoding/json" |
9 | 10 | )
|
10 | 11 |
|
11 | 12 | var graph Graph
|
@@ -403,3 +404,50 @@ func TestQueryStatistics(t *testing.T) {
|
403 | 404 | assert.Nil(t,err)
|
404 | 405 | assert.Equal(t, 1, res.RelationshipsDeleted(), "Expecting 1 relationships deleted")
|
405 | 406 | }
|
| 407 | + |
| 408 | +func testUtils(t *testing.T) { |
| 409 | + res := RandomString(10) |
| 410 | + assert.Equal(t, len(res), 10) |
| 411 | + |
| 412 | + res = ToString("test_string") |
| 413 | + assert.Equal(t, res, "test_string") |
| 414 | + |
| 415 | + res = ToString(10) |
| 416 | + assert.Equal(t, res, "10") |
| 417 | + |
| 418 | + res = ToString(1.2) |
| 419 | + assert.Equal(t, res, "1.2") |
| 420 | + |
| 421 | + res = ToString(true) |
| 422 | + assert.Equal(t, res, "true") |
| 423 | + |
| 424 | + res = ToString([3]int{1,2,3}) |
| 425 | + assert.Equal(t, res, "[1,2,3]") |
| 426 | + |
| 427 | + var jsonStr = ` |
| 428 | +{ |
| 429 | + "array": [ |
| 430 | + 1, |
| 431 | + 2, |
| 432 | + 3 |
| 433 | + ], |
| 434 | + "boolean": true, |
| 435 | + "null": null, |
| 436 | + "number": 123, |
| 437 | + "object": { |
| 438 | + "a": "b", |
| 439 | + "c": "d", |
| 440 | + "e": "f" |
| 441 | + }, |
| 442 | + "string": "Hello World" |
| 443 | +}` |
| 444 | + |
| 445 | + jsonMap := make(map[string]interface{}) |
| 446 | + err := json.Unmarshal([]byte(jsonStr), &jsonMap) |
| 447 | + if err != nil { |
| 448 | + panic(err) |
| 449 | + } |
| 450 | + |
| 451 | + res = ToString(jsonMap) |
| 452 | + assert.Equal(t, res, "{ array: [1,2,3],boolean: true,null: null,number: 123,object: {a: b,c: d,e: f},string: Hello World}") |
| 453 | +} |
0 commit comments