Skip to content

Commit 5ee58d6

Browse files
author
Jesse Michael
committed
swf configs
1 parent d69b2f2 commit 5ee58d6

File tree

4 files changed

+287
-0
lines changed

4 files changed

+287
-0
lines changed

swf_client_config.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package remoteconfig
2+
3+
type SimpleWorkflowClientConfig struct {
4+
Region *AWSRegion `json:"region,omitempty"`
5+
Endpoint *string `json:"endpoint,omitempty" remoteconfig:"optional"`
6+
DisableSSL *bool `json:"disable_ssl,omit" remoteconfig:"optional"`
7+
}
8+
9+
func (s SimpleWorkflowClientConfig) GetRegion() AWSRegion {
10+
return *s.Region
11+
}
12+
13+
func (s SimpleWorkflowClientConfig) GetEndpoint() string {
14+
if s.Endpoint != nil {
15+
return *s.Endpoint
16+
}
17+
return ""
18+
}
19+
20+
func (s SimpleWorkflowClientConfig) GetDisableSSL() bool {
21+
if s.DisableSSL != nil {
22+
return *s.DisableSSL
23+
}
24+
return false
25+
}

swf_client_config_test.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package remoteconfig
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/suite"
9+
)
10+
11+
const (
12+
VALID_SWF_CLIENT_REGION AWSRegion = AWS_REGION_US_EAST_1
13+
VALID_SWF_CLIENT_ENDPOINT string = "http://localhost:8000/swf"
14+
VALID_SWF_CLIENT_DISABLE_SSL bool = true
15+
)
16+
17+
type SimpleWorkflowClientConfigSuite struct {
18+
suite.Suite
19+
}
20+
21+
func TestSimpleWorkflowClientConfigSuite(t *testing.T) {
22+
suite.Run(t, new(SimpleWorkflowClientConfigSuite))
23+
}
24+
25+
func (s *SimpleWorkflowClientConfigSuite) SetupSuite() {
26+
}
27+
28+
func (s *SimpleWorkflowClientConfigSuite) SetupTest() {
29+
}
30+
31+
func (s *SimpleWorkflowClientConfigSuite) TestValidate() {
32+
region := VALID_SWF_CLIENT_REGION
33+
endpoint := VALID_SWF_CLIENT_ENDPOINT
34+
35+
c := &SimpleWorkflowClientConfig{
36+
Region: &region,
37+
Endpoint: &endpoint,
38+
}
39+
40+
err := validateConfigWithReflection(c)
41+
assert.Nil(s.T(), err)
42+
}
43+
44+
func (s *SimpleWorkflowClientConfigSuite) TestValidateWithoutEndpoint() {
45+
region := VALID_SWF_CLIENT_REGION
46+
47+
c := &SimpleWorkflowClientConfig{
48+
Region: &region,
49+
}
50+
51+
err := validateConfigWithReflection(c)
52+
assert.Nil(s.T(), err)
53+
}
54+
55+
func (s *SimpleWorkflowClientConfigSuite) TestValidateErrorEmptyEndpoint() {
56+
region := VALID_SWF_CLIENT_REGION
57+
endpoint := ""
58+
59+
c := &SimpleWorkflowClientConfig{
60+
Region: &region,
61+
Endpoint: &endpoint,
62+
}
63+
64+
err := validateConfigWithReflection(c)
65+
assert.NotNil(s.T(), err)
66+
assert.Equal(s.T(), errors.New("String Field: Endpoint, contains an empty string"), err)
67+
}
68+
69+
func (s *SimpleWorkflowClientConfigSuite) TestValidateErrorRegion() {
70+
region := AWSRegion("")
71+
72+
c := &SimpleWorkflowClientConfig{
73+
Region: &region,
74+
}
75+
76+
err := validateConfigWithReflection(c)
77+
assert.NotNil(s.T(), err)
78+
assert.Equal(s.T(), errors.New("Validater Field: Region, failed to validate with error, Region cannot be empty"), err)
79+
}
80+
81+
func (s *SimpleWorkflowClientConfigSuite) TestGetRegion() {
82+
region := VALID_SWF_CLIENT_REGION
83+
84+
c := &SimpleWorkflowClientConfig{
85+
Region: &region,
86+
}
87+
88+
assert.Equal(s.T(), VALID_SWF_CLIENT_REGION, c.GetRegion())
89+
}
90+
91+
func (s *SimpleWorkflowClientConfigSuite) TestGetEndpoint() {
92+
region := VALID_SWF_CLIENT_REGION
93+
endpoint := VALID_SWF_CLIENT_ENDPOINT
94+
95+
c := &SimpleWorkflowClientConfig{
96+
Region: &region,
97+
Endpoint: &endpoint,
98+
}
99+
100+
assert.Equal(s.T(), VALID_SWF_CLIENT_ENDPOINT, c.GetEndpoint())
101+
}
102+
103+
func (s *SimpleWorkflowClientConfigSuite) TestGetEndpointNotSet() {
104+
region := VALID_SWF_CLIENT_REGION
105+
106+
c := &SimpleWorkflowClientConfig{
107+
Region: &region,
108+
Endpoint: nil,
109+
}
110+
111+
assert.Equal(s.T(), "", c.GetEndpoint())
112+
}
113+
114+
func (s *SimpleWorkflowClientConfigSuite) TestGetDisableSSL() {
115+
region := VALID_SWF_CLIENT_REGION
116+
endpoint := VALID_SWF_CLIENT_ENDPOINT
117+
disableSSL := VALID_SWF_CLIENT_DISABLE_SSL
118+
119+
c := &SimpleWorkflowClientConfig{
120+
Region: &region,
121+
Endpoint: &endpoint,
122+
DisableSSL: &disableSSL,
123+
}
124+
125+
assert.Equal(s.T(), VALID_SWF_CLIENT_DISABLE_SSL, c.GetDisableSSL())
126+
}
127+
128+
func (s *SimpleWorkflowClientConfigSuite) TestGetDisableSSLNotSet() {
129+
region := VALID_SWF_CLIENT_REGION
130+
endpoint := VALID_SWF_CLIENT_ENDPOINT
131+
132+
c := &SimpleWorkflowClientConfig{
133+
Region: &region,
134+
Endpoint: &endpoint,
135+
DisableSSL: nil,
136+
}
137+
138+
assert.Equal(s.T(), false, c.GetDisableSSL())
139+
}

swf_workflow_config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package remoteconfig
2+
3+
type SimpleWorkflowConfig struct {
4+
Domain *string `json:"domain"`
5+
WorkflowType *WorkflowType `json:"workflow_type"`
6+
}
7+
8+
func (s SimpleWorkflowConfig) GetDomain() string {
9+
return *s.Domain
10+
}
11+
12+
func (s SimpleWorkflowConfig) GetWorkflowType() WorkflowType {
13+
return *s.WorkflowType
14+
}
15+
16+
type WorkflowType struct {
17+
Name *string `json:"name"`
18+
Version *string `json:"version"`
19+
}

swf_workflow_config_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package remoteconfig
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/suite"
9+
)
10+
11+
const (
12+
VALID_SWF_WORKFLOW_DOMAIN string = "testDomain"
13+
VALID_SWF_WORKFLOW_TYPE_NAME string = "testWorkflow"
14+
VALID_SWF_WORKFLOW_TYPE_VERSION string = "1.0"
15+
)
16+
17+
type SimpleWorkflowConfigSuite struct {
18+
suite.Suite
19+
}
20+
21+
func TestSimpleWorkflowConfigSuite(t *testing.T) {
22+
suite.Run(t, new(SimpleWorkflowConfigSuite))
23+
}
24+
25+
func (s *SimpleWorkflowConfigSuite) SetupSuite() {
26+
}
27+
28+
func (s *SimpleWorkflowConfigSuite) SetupTest() {
29+
}
30+
31+
func (s *SimpleWorkflowConfigSuite) TestValidate() {
32+
domain := VALID_SWF_WORKFLOW_DOMAIN
33+
name := VALID_SWF_WORKFLOW_TYPE_NAME
34+
version := VALID_SWF_WORKFLOW_TYPE_VERSION
35+
workflowType := WorkflowType{Name: &name, Version: &version}
36+
37+
c := &SimpleWorkflowConfig{
38+
Domain: &domain,
39+
WorkflowType: &workflowType,
40+
}
41+
42+
err := validateConfigWithReflection(c)
43+
assert.Nil(s.T(), err)
44+
}
45+
46+
func (s *SimpleWorkflowConfigSuite) TestValidateErrorDomain() {
47+
domain := ""
48+
name := VALID_SWF_WORKFLOW_TYPE_NAME
49+
version := VALID_SWF_WORKFLOW_TYPE_VERSION
50+
workflowType := WorkflowType{Name: &name, Version: &version}
51+
52+
c := &SimpleWorkflowConfig{
53+
Domain: &domain,
54+
WorkflowType: &workflowType,
55+
}
56+
57+
err := validateConfigWithReflection(c)
58+
assert.NotNil(s.T(), err)
59+
assert.Equal(s.T(), errors.New("String Field: Domain, contains an empty string"), err)
60+
}
61+
62+
func (s *SimpleWorkflowConfigSuite) TestGetDomain() {
63+
domain := VALID_SWF_WORKFLOW_DOMAIN
64+
name := VALID_SWF_WORKFLOW_TYPE_NAME
65+
version := VALID_SWF_WORKFLOW_TYPE_VERSION
66+
workflowType := WorkflowType{Name: &name, Version: &version}
67+
68+
c := &SimpleWorkflowConfig{
69+
Domain: &domain,
70+
WorkflowType: &workflowType,
71+
}
72+
73+
assert.Equal(s.T(), VALID_SWF_WORKFLOW_DOMAIN, c.GetDomain())
74+
}
75+
76+
func (s *SimpleWorkflowConfigSuite) TestValidateErrorWorkflowType() {
77+
domain := VALID_SWF_WORKFLOW_DOMAIN
78+
name := ""
79+
version := ""
80+
workflowType := WorkflowType{Name: &name, Version: &version}
81+
82+
c := &SimpleWorkflowConfig{
83+
Domain: &domain,
84+
WorkflowType: &workflowType,
85+
}
86+
87+
err := validateConfigWithReflection(c)
88+
assert.NotNil(s.T(), err)
89+
assert.Equal(s.T(), errors.New("Sub Field of WorkflowType, failed to validate with error, String Field: Name, contains an empty string"), err)
90+
}
91+
92+
func (s *SimpleWorkflowConfigSuite) TestGetWorkflowType() {
93+
domain := VALID_SWF_WORKFLOW_DOMAIN
94+
name := VALID_SWF_WORKFLOW_TYPE_NAME
95+
version := VALID_SWF_WORKFLOW_TYPE_VERSION
96+
workflowType := WorkflowType{Name: &name, Version: &version}
97+
98+
c := &SimpleWorkflowConfig{
99+
Domain: &domain,
100+
WorkflowType: &workflowType,
101+
}
102+
103+
assert.Equal(s.T(), workflowType, c.GetWorkflowType())
104+
}

0 commit comments

Comments
 (0)