forked from mantzas/patron
-
Notifications
You must be signed in to change notification settings - Fork 67
/
integration_test.go
49 lines (43 loc) · 954 Bytes
/
integration_test.go
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
//go:build integration
package patron
import (
"context"
"errors"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestServer_Run_Shutdown(t *testing.T) {
tests := map[string]struct {
cp Component
wantErr bool
}{
"success": {cp: &testComponent{}, wantErr: false},
"failed to run": {cp: &testComponent{errorRunning: true}, wantErr: true},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
defer func() {
os.Clearenv()
}()
t.Setenv("PATRON_HTTP_DEFAULT_PORT", "50099")
svc, err := New("test", "", WithJSONLogger())
require.NoError(t, err)
err = svc.Run(context.Background(), tt.cp)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}
type testComponent struct {
errorRunning bool
}
func (ts testComponent) Run(_ context.Context) error {
if ts.errorRunning {
return errors.New("failed to run component")
}
return nil
}