navidrome/api/api_test.go

36 lines
838 B
Go
Raw Normal View History

2016-02-28 00:42:08 +01:00
package api_test
2016-02-25 00:24:06 +01:00
import (
"fmt"
"github.com/astaxie/beego"
2016-03-02 19:18:39 +01:00
_ "github.com/deluan/gosonic/conf"
"net/http"
2016-02-26 00:52:07 +01:00
"net/http/httptest"
2016-03-01 22:05:49 +01:00
"strings"
2016-02-25 00:24:06 +01:00
)
const (
2016-03-02 19:18:39 +01:00
testUser = "deluan"
testPassword = "wordpass"
2016-03-02 19:18:39 +01:00
testClient = "test"
testVersion = "1.0.0"
)
2016-03-01 22:05:49 +01:00
func AddParams(endpoint string, params ...string) string {
url := fmt.Sprintf("%s?u=%s&p=%s&c=%s&v=%s&f=json", endpoint, testUser, testPassword, testClient, testVersion)
2016-03-01 22:05:49 +01:00
if len(params) > 0 {
url = url + "&" + strings.Join(params, "&")
}
return url
}
2016-02-25 00:33:13 +01:00
func Get(url string, testCase string) (*http.Request, *httptest.ResponseRecorder) {
2016-02-25 00:24:06 +01:00
r, _ := http.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
2016-02-25 17:14:16 +01:00
beego.Debug("testing", testCase, fmt.Sprintf("\nUrl: %s\nStatus Code: [%d]\n%s", r.URL, w.Code, w.Body.String()))
2016-02-25 00:24:06 +01:00
return r, w
}