Files
Go-Web-Template/server/utils/json_test.go

54 lines
939 B
Go

package utils
import (
"fmt"
"testing"
)
func TestGetJSONKeys(t *testing.T) {
var jsonStr = `
{
"Name": "test",
"TableName": "test",
"TemplateID": "test",
"TemplateInfo": "test",
"Limit": 0
}`
keys, err := GetJSONKeys(jsonStr)
if err != nil {
t.Errorf("GetJSONKeys failed: %v", err)
return
}
if len(keys) != 5 {
t.Errorf("GetJSONKeys unexpected key count: %d", len(keys))
return
}
if keys[0] != "Name" {
t.Errorf("GetJSONKeys unexpected first key: %s", keys[0])
return
}
if keys[1] != "TableName" {
t.Errorf("GetJSONKeys unexpected second key: %s", keys[1])
return
}
if keys[2] != "TemplateID" {
t.Errorf("GetJSONKeys unexpected third key: %s", keys[2])
return
}
if keys[3] != "TemplateInfo" {
t.Errorf("GetJSONKeys unexpected fourth key: %s", keys[3])
return
}
if keys[4] != "Limit" {
t.Errorf("GetJSONKeys unexpected fifth key: %s", keys[4])
return
}
fmt.Println(keys)
}