1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-13 07:07:59 +01:00
ntfy/server/server_test.go

37 lines
724 B
Go
Raw Normal View History

2021-12-07 18:23:42 +01:00
package server
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"heckel.io/ntfy/config"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestServer_Publish(t *testing.T) {
s := newTestServer(t, newTestConfig())
rr := httptest.NewRecorder()
req, _ := http.NewRequest("PUT", "/mytopic", strings.NewReader("my message"))
s.handle(rr, req)
var m message
assert.Nil(t, json.NewDecoder(rr.Body).Decode(&m))
assert.NotEmpty(t, m.ID)
assert.Equal(t, "my message", m.Message)
}
func newTestConfig() *config.Config {
return config.New(":80")
}
func newTestServer(t *testing.T, config *config.Config) *Server {
server, err := New(config)
if err != nil {
t.Fatal(err)
}
return server
}