~bigbes/sr-ht-ecore

ref: 92fea80afcf9d123988f58fbf2aea125124d7a1c sr-ht-ecore/pages/error_test.go -rw-r--r-- 982 bytes
92fea80a — Eugene Blikh benchmarks for the hot path 2 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))
}