-
Notifications
You must be signed in to change notification settings - Fork 22
/
env_docker_test.go
76 lines (70 loc) · 1.87 KB
/
env_docker_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
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
// Copyright (c) The EfficientGo Authors.
// Licensed under the Apache License 2.0.
package e2e
import (
"testing"
"github.com/efficientgo/core/errors"
"github.com/efficientgo/core/testutil"
)
func TestGetDockerPortMapping(t *testing.T) {
for _, tcase := range []struct {
out string
expectedPort int
expectedErr error
}{
{out: "0.0.0.0:2313", expectedPort: 2313},
{out: "error", expectedErr: errors.New("got unexpected output: error")},
{out: ` 0.0.0.0:49154
:::49154`, expectedPort: 49154},
} {
t.Run("", func(t *testing.T) {
l, err := getDockerPortMapping([]byte(tcase.out))
if tcase.expectedErr != nil {
testutil.NotOk(t, err)
testutil.Equals(t, tcase.expectedErr.Error(), err.Error())
return
}
testutil.Ok(t, err)
testutil.Equals(t, tcase.expectedPort, l)
})
}
}
func TestValidateName(t *testing.T) {
for _, tcase := range []struct {
name string
expectedErr error
}{
{
name: "",
expectedErr: errors.New("name can't be smaller than 1 or over 16 character long due to docker network name constraints, got: "),
},
{
name: "e2e-testName",
},
{
name: "e2e_testName",
expectedErr: errors.New("name can have only ^[-a-zA-Z\\d]{1,16}$ characters due to docker network name constraints, got: e2e_testName"),
},
{
name: "e2e_testNamelongerthanexpected",
expectedErr: errors.New("name can't be smaller than 1 or over 16 character long due to docker network name constraints, got: e2e_testNamelongerthanexpected"),
},
{
name: func() string {
n, err := generateName()
testutil.Ok(t, err)
return n
}(),
},
} {
t.Run("", func(t *testing.T) {
err := validateName(tcase.name)
if tcase.expectedErr != nil {
testutil.NotOk(t, err)
testutil.Equals(t, tcase.expectedErr.Error(), err.Error())
return
}
testutil.Ok(t, err)
})
}
}