[MM-61465] Fix errcheck issues in server/channels/app/post_metadata_test.go (#29206)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c2c2a1eaba
Коммит
73f1383f5f
@@ -135,7 +135,6 @@ issues:
|
||||
channels/app/post.go|\
|
||||
channels/app/post_helpers_test.go|\
|
||||
channels/app/post_metadata.go|\
|
||||
channels/app/post_metadata_test.go|\
|
||||
channels/app/post_persistent_notification_test.go|\
|
||||
channels/app/post_test.go|\
|
||||
channels/app/product_notices_test.go|\
|
||||
|
||||
@@ -71,7 +71,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
switch r.URL.Path {
|
||||
case "/":
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html>
|
||||
<head>
|
||||
<meta property="og:image" content="` + serverURL + `/test-image3.png" />
|
||||
@@ -82,24 +82,28 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
<meta property="og:description" content="Contribute to hmhealey/test-files development by creating an account on GitHub." />
|
||||
</head>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
case "/test-image1.png":
|
||||
file, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
case "/test-image2.png":
|
||||
file, err := testutils.ReadTestFile("test-data-graph.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
case "/test-image3.png":
|
||||
file, err := testutils.ReadTestFile("qa-data-graph.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
default:
|
||||
require.Fail(t, "Invalid path", r.URL.Path)
|
||||
}
|
||||
@@ -916,7 +920,7 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
|
||||
switch r.URL.Path {
|
||||
case "/":
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html>
|
||||
<head>
|
||||
<meta property="og:image" content="` + serverURL + `/test-image3.png" />
|
||||
@@ -927,12 +931,14 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
|
||||
<meta property="og:description" content="Contribute to hmhealey/test-files development by creating an account on GitHub." />
|
||||
</head>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
case "/test-image3.png":
|
||||
file, err := testutils.ReadTestFile("qa-data-graph.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
default:
|
||||
require.Fail(t, "Invalid path", r.URL.Path)
|
||||
}
|
||||
@@ -978,35 +984,39 @@ func TestGetEmbedForPost(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
if r.Header.Get("Accept-Language") == "fr" {
|
||||
w.Header().Set("Content-Language", "fr")
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html>
|
||||
<head>
|
||||
<meta property="og:title" content="Title-FR" />
|
||||
<meta property="og:description" content="Bonjour le monde" />
|
||||
</head>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html>
|
||||
<head>
|
||||
<meta property="og:title" content="Title" />
|
||||
<meta property="og:description" content="Hello world" />
|
||||
</head>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
} else if r.URL.Path == "/image.png" {
|
||||
file, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
} else if r.URL.Path == "/other" {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Fail(t, "Invalid path", r.URL.Path)
|
||||
}
|
||||
@@ -1158,7 +1168,8 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Write(file)
|
||||
_, err = w.Write(file)
|
||||
require.NoError(t, err)
|
||||
}))
|
||||
|
||||
post := &model.Post{
|
||||
@@ -1214,7 +1225,8 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
img := image.NewGray(image.Rect(0, 0, 200, 300))
|
||||
|
||||
var encoder png.Encoder
|
||||
encoder.Encode(w, img)
|
||||
err := encoder.Encode(w, img)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
@@ -1268,7 +1280,8 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
img := image.NewGray(image.Rect(0, 0, 300, 400))
|
||||
|
||||
var encoder png.Encoder
|
||||
encoder.Encode(w, img)
|
||||
err := encoder.Encode(w, img)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
@@ -1322,7 +1335,8 @@ func TestGetImagesForPost(t *testing.T) {
|
||||
img := image.NewGray(image.Rect(0, 0, 400, 500))
|
||||
|
||||
var encoder png.Encoder
|
||||
encoder.Encode(w, img)
|
||||
err := encoder.Encode(w, img)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
@@ -2042,13 +2056,14 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
|
||||
var encoder png.Encoder
|
||||
|
||||
encoder.Encode(w, img)
|
||||
err := encoder.Encode(w, img)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
writeHTML := func(title string) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
w.Write([]byte(`
|
||||
_, err := w.Write([]byte(`
|
||||
<html prefix="og:http://ogp.me/ns#">
|
||||
<head>
|
||||
<meta property="og:title" content="` + title + `" />
|
||||
@@ -2056,6 +2071,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
<body>
|
||||
</body>
|
||||
</html>`))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(r.URL.Path, "/image") {
|
||||
@@ -2068,16 +2084,19 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
} else if strings.HasPrefix(r.URL.Path, "/json") {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
w.Write([]byte("true"))
|
||||
_, err := w.Write([]byte("true"))
|
||||
require.NoError(t, err)
|
||||
} else if strings.HasPrefix(r.URL.Path, "/timeout") {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
w.Write([]byte("<html>"))
|
||||
_, err := w.Write([]byte("<html>"))
|
||||
require.NoError(t, err)
|
||||
select {
|
||||
case <-time.After(60 * time.Second):
|
||||
case <-r.Context().Done():
|
||||
}
|
||||
w.Write([]byte("</html>"))
|
||||
_, err = w.Write([]byte("</html>"))
|
||||
require.NoError(t, err)
|
||||
} else if strings.HasPrefix(r.URL.Path, "/mixed") {
|
||||
for _, acceptedType := range r.Header["Accept"] {
|
||||
if strings.HasPrefix(acceptedType, "image/*") || strings.HasPrefix(acceptedType, "image/png") {
|
||||
|
||||
Ссылка в новой задаче
Block a user