~bigbes/sr-ht-ecore

ref: 9a97b126e5a4f23591b42da7d75b0bb843c31521 sr-ht-ecore/pages/error_test.go -rw-r--r-- 982 bytes
9a97b126 — Eugene Blikh ecore: the gaps the third adoption pass found 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package pages

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
)

// TestAPIMessageMirrorsMessage keeps the two registers on one table: a status
// that has a sentence for a reader must have a word for a parser, or a REST
// surface silently falls back to its own spelling.
func TestAPIMessageMirrorsMessage(t *testing.T) {
	for _, status := range []int{
		http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound,
		http.StatusMethodNotAllowed, http.StatusInternalServerError,
		http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout,
	} {
		assert.NotEmpty(t, Message(status), "page sentence for %d", status)
		assert.NotEmpty(t, APIMessage(status), "machine word for %d", status)
		assert.NotEqual(t, Message(status), APIMessage(status),
			"%d: a parser and a reader are not the same audience", status)
	}

	assert.Empty(t, APIMessage(http.StatusTeapot))
	assert.Equal(t, "not found", APIMessage(http.StatusNotFound))
}