k3s/pkg/util/util_test.go

42 lines
761 B
Go
Raw Normal View History

2014-06-09 14:16:43 +00:00
package util
import (
"encoding/json"
2014-06-11 19:50:01 +00:00
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
2014-06-09 14:16:43 +00:00
)
func TestMakeJSONString(t *testing.T) {
pod := api.Pod{
2014-06-11 19:50:01 +00:00
JSONBase: api.JSONBase{ID: "foo"},
2014-06-09 14:16:43 +00:00
Labels: map[string]string{
"foo": "bar",
"baz": "blah",
},
}
2014-06-11 19:50:01 +00:00
2014-06-09 14:16:43 +00:00
body := MakeJSONString(pod)
2014-06-11 19:50:01 +00:00
2014-06-09 14:16:43 +00:00
expectedBody, err := json.Marshal(pod)
expectNoError(t, err)
if string(expectedBody) != body {
t.Errorf("JSON doesn't match. Expected %s, saw %s", expectedBody, body)
}
}
func TestHandleCrash(t *testing.T) {
count := 0
expect := 10
for i := 0; i < expect; i = i + 1 {
defer HandleCrash()
2014-06-11 19:50:01 +00:00
if i%2 == 0 {
2014-06-09 14:16:43 +00:00
panic("Test Panic")
}
count = count + 1
}
if count != expect {
t.Errorf("Expected %d iterations, found %d", expect, count)
}
}