blob: 0a511d00d8944af7f3912a03c626f28476c790e6 [file] [log] [blame]
package alerts
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"go.skia.org/infra/go/testutils"
)
type testDirStruct struct {
Direction Direction
}
func TestDirectionJSON(t *testing.T) {
testutils.SmallTest(t)
ts := testDirStruct{
Direction: UP,
}
b, err := json.Marshal(ts)
assert.NoError(t, err)
assert.Equal(t, "{\"Direction\":\"UP\"}", string(b))
target := &testDirStruct{}
err = json.Unmarshal(b, target)
assert.NoError(t, err)
assert.Equal(t, UP, target.Direction)
target = &testDirStruct{}
err = json.Unmarshal([]byte("{\"Direction\":\"NOT A VALID VALUE\"}"), target)
assert.NoError(t, err)
assert.Equal(t, BOTH, target.Direction)
}