-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi_endpoint_config_test.go
97 lines (75 loc) · 2.29 KB
/
api_endpoint_config_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package remoteconfig
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
const (
VALID_API_ENDPOINT_BASE_PATH string = "http://basepath"
VALID_API_ENDPOINT_SUB_PATH string = "sub/path"
VALID_API_ENDPOINT_ID string = "testid"
)
var (
VALID_API_ENDPOINT_FULL_PATH string = fmt.Sprintf("%s/%s", VALID_API_ENDPOINT_BASE_PATH, VALID_API_ENDPOINT_SUB_PATH)
VALID_API_ENDPOINT_FULL_PATH_WITH_ID string = fmt.Sprintf("%s/%s/%s", VALID_API_ENDPOINT_BASE_PATH, VALID_API_ENDPOINT_SUB_PATH, VALID_API_ENDPOINT_ID)
)
type APIEndpointConfigSuite struct {
suite.Suite
}
func TestAPIEndpointConfigSuite(t *testing.T) {
suite.Run(t, new(APIEndpointConfigSuite))
}
func (s *APIEndpointConfigSuite) SetupSuite() {
}
func (s *APIEndpointConfigSuite) SetupTest() {
}
func (s *APIEndpointConfigSuite) TestValidate() {
basePath := VALID_API_ENDPOINT_BASE_PATH
subPath := VALID_API_ENDPOINT_SUB_PATH
a := &APIEndpointConfig{
BasePath: &basePath,
SubPath: &subPath,
}
err := validateConfigWithReflection(a)
assert.Nil(s.T(), err)
}
func (s *APIEndpointConfigSuite) TestValidateErrorBasePathNotSet() {
a := &APIEndpointConfig{
BasePath: nil,
}
err := validateConfigWithReflection(a)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), errors.New("Field: BasePath, not set"), err)
}
func (s *APIEndpointConfigSuite) TestValidateErrorSubPathNotSet() {
basePath := VALID_API_ENDPOINT_BASE_PATH
a := &APIEndpointConfig{
BasePath: &basePath,
SubPath: nil,
}
err := validateConfigWithReflection(a)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), errors.New("Field: SubPath, not set"), err)
}
func (s *APIEndpointConfigSuite) TestGetFullPath() {
basePath := VALID_API_ENDPOINT_BASE_PATH
subPath := VALID_API_ENDPOINT_SUB_PATH
a := &APIEndpointConfig{
BasePath: &basePath,
SubPath: &subPath,
}
fullPath := a.GetFullPath()
assert.Equal(s.T(), VALID_API_ENDPOINT_FULL_PATH, fullPath)
}
func (s *APIEndpointConfigSuite) TestGetFullPathWithID() {
basePath := VALID_API_ENDPOINT_BASE_PATH
subPath := VALID_API_ENDPOINT_SUB_PATH
a := &APIEndpointConfig{
BasePath: &basePath,
SubPath: &subPath,
}
fullPathWithID := a.GetFullPathWithID(VALID_API_ENDPOINT_ID)
assert.Equal(s.T(), VALID_API_ENDPOINT_FULL_PATH_WITH_ID, fullPathWithID)
}