-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver_test.go
More file actions
59 lines (47 loc) · 1.1 KB
/
server_test.go
File metadata and controls
59 lines (47 loc) · 1.1 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package proxytv
import (
"io"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestServerStartStop(t *testing.T) {
// Create a mock provider
provider := &Provider{}
// Create a config
config := &Config{
ListenAddress: ":8080",
UseFFMPEG: true,
MaxStreams: 10,
}
// Create a new server
server, err := NewServer(config, provider, "test")
require.NoError(t, err)
// Start the server
errChan := server.Start(provider)
// Create a test HTTP client
client := &http.Client{
Timeout: 2 * time.Second,
}
// Test the /ping endpoint
t.Run("Ping", func(t *testing.T) {
resp, err := client.Get("http://localhost:8080/ping")
require.NoError(t, err)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "PONG", string(body))
assert.Equal(t, http.StatusOK, resp.StatusCode)
})
// Stop the server
err = server.Stop()
require.NoError(t, err)
// Check if there were any errors during server run
select {
case err := <-errChan:
assert.NoError(t, err)
default:
}
}