33 lines
762 B
Go
33 lines
762 B
Go
package middleware
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAppInfo(t *testing.T) {
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, err := w.Write([]byte("resp"))
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
server := httptest.NewServer(AppInfo("tapp", "tversion")(handler))
|
|
defer server.Close()
|
|
|
|
res, err := http.Get(server.URL)
|
|
require.Nil(t, err)
|
|
defer res.Body.Close()
|
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
|
assert.Equal(t, "tapp", res.Header.Get("App-Name"))
|
|
assert.Equal(t, "tversion", res.Header.Get("App-Version"))
|
|
|
|
b, err := io.ReadAll(res.Body)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "resp", string(b))
|
|
}
|