mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-30 10:25:40 +02:00
Tests for cliet package
This commit is contained in:
parent
6a7e9071b6
commit
fe5734d9f0
8 changed files with 162 additions and 43 deletions
test
38
test/server.go
Normal file
38
test/server.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"heckel.io/ntfy/server"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
// StartServer starts a server.Server with a random port and waits for the server to be up
|
||||
func StartServer(t *testing.T) (*server.Server, int) {
|
||||
port := 10000 + rand.Intn(20000)
|
||||
conf := server.NewConfig()
|
||||
conf.ListenHTTP = fmt.Sprintf(":%d", port)
|
||||
s, err := server.New(conf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
if err := s.Run(); err != nil && err != http.ErrServerClosed {
|
||||
panic(err) // 'go vet' complains about 't.Fatal(err)'
|
||||
}
|
||||
}()
|
||||
WaitForPortUp(t, port)
|
||||
return s, port
|
||||
}
|
||||
|
||||
// StopServer stops the test server and waits for the port to be down
|
||||
func StopServer(t *testing.T, s *server.Server, port int) {
|
||||
s.Stop()
|
||||
WaitForPortDown(t, port)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue