GameShow/questions/storage/question_test.go

35 lines
588 B
Go
Executable File

package storage
import (
"encoding/json"
"testing"
)
func TestUnmarshalQuestionObject(t *testing.T) {
raw := `{"text":"text here", "id":"id here"}`
var a Question
if err := json.Unmarshal([]byte(raw), &a); err != nil {
t.Fatal(err)
}
if a.Text != "text here" {
t.Fatal(a.Text)
}
if a.ID != "id here" {
t.Fatal(a.ID)
}
}
func TestUnmarshalQuestionString(t *testing.T) {
raw := `"text here"`
var a Question
if err := json.Unmarshal([]byte(raw), &a); err != nil {
t.Fatal(err)
}
if a.ID != "text here" {
t.Fatal(a.ID)
}
if a.Text != "" {
t.Fatal(a.Text)
}
}