gomusic/routes_test.go

30 lines
694 B
Go

package main
import (
"net/http"
"net/http/httptest"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPingRoute(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ping", nil)
router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.Equal(t, "pong", w.Body.String())
}
func TestGetArtistByIDRoute(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/artists/0TnOYISbd1XYRBk9myaseg", nil)
router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.Equal(t, `{"ID":"0TnOYISbd1XYRBk9myaseg","Name":"Pitbull","Popularity":83,"Genres":[]}`, w.Body.String())
}