mattermost-plugin-bridge-xmpp/server/plugin_test.go

29 lines
570 B
Go

package main
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestServeHTTP(t *testing.T) {
a := assert.New(t)
plugin := Plugin{}
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/api/v1/hello", http.NoBody)
r.Header.Set("Mattermost-User-ID", "test-user-id")
plugin.ServeHTTP(nil, w, r)
result := w.Result()
a.NotNil(result)
defer result.Body.Close()
bodyBytes, err := io.ReadAll(result.Body)
a.Nil(err)
bodyString := string(bodyBytes)
a.Equal("Hello, world!", bodyString)
}