-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfire_event_lifecycle_test.go
More file actions
43 lines (33 loc) · 1 KB
/
Copy pathfire_event_lifecycle_test.go
File metadata and controls
43 lines (33 loc) · 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
package gomeassistant
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func newFireEventLifecycleTestApp(t *testing.T) *App {
t.Helper()
app, err := NewApp(context.Background(), NewAppRequest{
URL: "http://127.0.0.1:1",
HAAuthToken: "token",
})
require.NoError(t, err)
return app
}
func TestFireEventRejectsInactiveAppLifecycles(t *testing.T) {
t.Run("before Start", func(t *testing.T) {
app := newFireEventLifecycleTestApp(t)
require.ErrorIs(t, app.FireEvent("test_event", nil), ErrAppNotRunning)
})
t.Run("after Start returns", func(t *testing.T) {
app := newFireEventLifecycleTestApp(t)
ctx, cancel := context.WithCancel(context.Background())
cancel()
require.ErrorIs(t, app.Start(ctx), context.Canceled)
require.ErrorIs(t, app.FireEvent("test_event", nil), ErrAppNotRunning)
})
t.Run("after Cleanup", func(t *testing.T) {
app := newFireEventLifecycleTestApp(t)
app.Cleanup()
require.ErrorIs(t, app.FireEvent("test_event", nil), ErrAppClosed)
})
}