add more unit tests

This commit is contained in:
Sabrina
2020-01-27 15:28:48 -08:00
parent 31f386e220
commit 3fcc899200

View File

@@ -42,6 +42,11 @@ func TestNew(t *testing.T) {
t.Errorf("got %v\nwant %v", err, expected) t.Errorf("got %v\nwant %v", err, expected)
} }
_, actual := New(nil)
if actual == nil || actual.Error() != "unexpected end of JSON input" {
t.Errorf("got %v\nwant %v", actual, expected)
}
_, err = New(jsonKey) _, err = New(jsonKey)
if err != nil { if err != nil {
t.Errorf("got %#v", err) t.Errorf("got %#v", err)
@@ -60,7 +65,7 @@ func TestNewWithClient(t *testing.T) {
} }
} }
func TestNewWithNoClient(t *testing.T) { func TestNewWithClientErrors(t *testing.T) {
t.Parallel() t.Parallel()
expected := errors.New("client is nil") expected := errors.New("client is nil")
@@ -69,6 +74,14 @@ func TestNewWithNoClient(t *testing.T) {
t.Errorf("got %v\nwant %v", actual, expected) t.Errorf("got %v\nwant %v", actual, expected)
} }
ctx := context.Background()
httpClient := urlfetch.Client(ctx)
_, actual = NewWithClient(nil, httpClient)
if actual == nil || actual.Error() != "unexpected end of JSON input" {
t.Errorf("got %v\nwant %v", actual, expected)
}
} }
func TestAcknowledgeSubscription(t *testing.T) { func TestAcknowledgeSubscription(t *testing.T) {