forked from elgohr/go-localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalstack_internal_test.go
More file actions
82 lines (78 loc) · 2.04 KB
/
Copy pathlocalstack_internal_test.go
File metadata and controls
82 lines (78 loc) · 2.04 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package localstack
import (
"errors"
"github.com/elgohr/go-localstack/internal/internalfakes"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
"os"
"testing"
)
func TestInstance_Start_Fails(t *testing.T) {
for _, tt := range [...]struct {
name string
given func() *Instance
then func(err error)
}{
{
name: "can't restart localstack when already running",
given: func() *Instance {
fakePool := &internalfakes.FakePool{}
fakePool.PurgeReturns(errors.New("can't start"))
return &Instance{
pool: fakePool,
resource: &dockertest.Resource{},
}
},
then: func(err error) {
require.EqualError(t, err, "localstack: can't stop an already running instance: can't start")
},
},
{
name: "can't start container",
given: func() *Instance {
fakePool := &internalfakes.FakePool{}
fakePool.RunWithOptionsReturns(nil, errors.New("can't start container"))
return &Instance{
pool: fakePool,
}
},
then: func(err error) {
require.EqualError(t, err, "localstack: could not start container: can't start container")
},
},
{
name: "fails during waiting on startup",
given: func() *Instance {
fakePool := &internalfakes.FakePool{}
fakePool.RetryReturns(errors.New("can't wait"))
return &Instance{
pool: fakePool,
}
},
then: func(err error) {
require.EqualError(t, err, "localstack: could not start environment: can't wait")
},
},
} {
t.Run(tt.name, func(t *testing.T) {
tt.then(tt.given().Start())
})
}
}
func TestInstance_Stop_Fails(t *testing.T) {
fakePool := &internalfakes.FakePool{}
fakePool.PurgeReturns(errors.New("can't stop"))
i := &Instance{
pool: fakePool,
resource: &dockertest.Resource{},
}
require.EqualError(t, i.Stop(), "can't stop")
}
func TestInstance_isAvailable_Session_Fails(t *testing.T) {
if err := os.Setenv("AWS_STS_REGIONAL_ENDPOINTS", "FAILURE"); err != nil {
t.Fatal(err)
}
defer os.Unsetenv("AWS_STS_REGIONAL_ENDPOINTS")
i := &Instance{}
require.Error(t, i.isAvailable())
}