Adding upstream version 2.52.6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
a960158181
commit
6d002e9543
441 changed files with 95392 additions and 0 deletions
58
utils/json_test.go
Normal file
58
utils/json_test.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type sampleStructure struct {
|
||||
ImportantString string `json:"important_string"`
|
||||
}
|
||||
|
||||
func Test_GolangJSONEncoder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
ss = &sampleStructure{
|
||||
ImportantString: "Hello World",
|
||||
}
|
||||
importantString = `{"important_string":"Hello World"}`
|
||||
jsonEncoder JSONMarshal = json.Marshal
|
||||
)
|
||||
|
||||
raw, err := jsonEncoder(ss)
|
||||
AssertEqual(t, err, nil)
|
||||
|
||||
AssertEqual(t, string(raw), importantString)
|
||||
}
|
||||
|
||||
func Test_DefaultJSONEncoder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
ss = &sampleStructure{
|
||||
ImportantString: "Hello World",
|
||||
}
|
||||
importantString = `{"important_string":"Hello World"}`
|
||||
jsonEncoder JSONMarshal = json.Marshal
|
||||
)
|
||||
|
||||
raw, err := jsonEncoder(ss)
|
||||
AssertEqual(t, err, nil)
|
||||
|
||||
AssertEqual(t, string(raw), importantString)
|
||||
}
|
||||
|
||||
func Test_DefaultJSONDecoder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
ss sampleStructure
|
||||
importantString = []byte(`{"important_string":"Hello World"}`)
|
||||
jsonDecoder JSONUnmarshal = json.Unmarshal
|
||||
)
|
||||
|
||||
err := jsonDecoder(importantString, &ss)
|
||||
AssertEqual(t, err, nil)
|
||||
AssertEqual(t, "Hello World", ss.ImportantString)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue