license, openGraph tests: convert to testify (#12919)

Этот коммит содержится в:
Luke Kingland
2019-10-31 20:19:19 +09:00
коммит произвёл Ben Schumacher
родитель 8c3dcadbd7
Коммит 6f6eb13a47
2 изменённых файлов: 18 добавлений и 23 удалений

Просмотреть файл

@@ -4,6 +4,8 @@ import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
)
@@ -15,22 +17,22 @@ func TestGetOldClientLicense(t *testing.T) {
license, resp := Client.GetOldClientLicense("")
CheckNoError(t, resp)
if len(license["IsLicensed"]) == 0 {
t.Fatal("license not returned correctly")
}
require.NotEqual(t, license["IsLicensed"], "", "license not returned correctly")
Client.Logout()
_, resp = Client.GetOldClientLicense("")
CheckNoError(t, resp)
if _, err := Client.DoApiGet("/license/client", ""); err == nil || err.StatusCode != http.StatusNotImplemented {
t.Fatal("should have errored with 501")
}
_, err := Client.DoApiGet("/license/client", "")
require.Error(t, err, "get /license/client did not return an error")
require.Equal(t, err.StatusCode, http.StatusNotImplemented,
"expected 501 Not Implemented")
if _, err := Client.DoApiGet("/license/client?format=junk", ""); err == nil || err.StatusCode != http.StatusBadRequest {
t.Fatal("should have errored with 400")
}
_, err = Client.DoApiGet("/license/client?format=junk", "")
require.Error(t, err, "get /license/client?format=junk did not return an error")
require.Equal(t, err.StatusCode, http.StatusBadRequest,
"expected 400 Bad Request")
license, resp = th.SystemAdminClient.GetOldClientLicense("")
CheckNoError(t, resp)

Просмотреть файл

@@ -7,10 +7,10 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
)
@@ -61,19 +61,12 @@ func TestGetOpenGraphMetadata(t *testing.T) {
openGraph, resp := Client.OpenGraph(ts.URL + data["path"].(string))
CheckNoError(t, resp)
if strings.Compare(openGraph["title"], data["title"].(string)) != 0 {
t.Fatal(fmt.Sprintf(
"OG data title mismatch for path \"%s\". Expected title: \"%s\". Actual title: \"%s\"",
data["path"].(string), data["title"].(string), openGraph["title"],
))
}
if ogDataCacheMissCount != data["cacheMissCount"].(int) {
t.Fatal(fmt.Sprintf(
"Cache miss count didn't match. Expected value %d. Actual value %d.",
data["cacheMissCount"].(int), ogDataCacheMissCount,
))
}
require.Equalf(t, openGraph["title"], data["title"].(string),
"OG data title mismatch for path \"%s\".")
require.Equal(t, ogDataCacheMissCount, data["cacheMissCount"].(int),
"Cache miss count didn't match.")
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = false })