Skip to content

Commit 72a03dc

Browse files
committed
feat(release): add query release version
1 parent b87b62f commit 72a03dc

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
)
1111

1212
// List lists an app's config.
13-
func List(c *drycc.Client, app string) (api.Config, error) {
13+
func List(c *drycc.Client, app string, version int) (api.Config, error) {
1414
u := fmt.Sprintf("/v2/apps/%s/config/", app)
15+
if version > 0 {
16+
u = fmt.Sprintf("%s?version=v%d", u, version)
17+
}
1518

1619
res, reqErr := c.Request("GET", u, nil)
1720
if reqErr != nil {

config/config_test.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/drycc/controller-sdk-go/api"
1313
)
1414

15-
const configFixture string = `
15+
const configFixtureV1 string = `
1616
{
1717
"owner": "test",
1818
"app": "example-go",
@@ -42,6 +42,37 @@ const configFixture string = `
4242
}
4343
`
4444

45+
const configFixtureV2 string = `
46+
{
47+
"owner": "test",
48+
"app": "example-go",
49+
"values": {
50+
"TEST": "testing",
51+
"FOO": "bar",
52+
"VERSION": "2"
53+
},
54+
"typed_values": {
55+
"web": {
56+
"PORT": "9000"
57+
}
58+
},
59+
"limits": {
60+
"web": "std1.xlarge.c1m1"
61+
},
62+
"tags": {
63+
"web": {
64+
"test": "tests"
65+
}
66+
},
67+
"registry": {
68+
"username": "bob"
69+
},
70+
"created": "2014-01-01T00:00:00UTC",
71+
"updated": "2014-01-01T00:00:00UTC",
72+
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
73+
}
74+
`
75+
4576
const configUnsetFixture string = `
4677
{
4778
"owner": "test",
@@ -82,7 +113,7 @@ func (f *fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
82113
}
83114

84115
res.WriteHeader(http.StatusCreated)
85-
res.Write([]byte(configFixture))
116+
res.Write([]byte(configFixtureV1))
86117
return
87118
}
88119

@@ -108,7 +139,12 @@ func (f *fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
108139
}
109140

110141
if req.URL.Path == "/v2/apps/example-go/config/" && req.Method == "GET" {
111-
res.Write([]byte(configFixture))
142+
143+
if req.URL.RawQuery == "version=v2" {
144+
res.Write([]byte(configFixtureV2))
145+
} else {
146+
res.Write([]byte(configFixtureV1))
147+
}
112148
return
113149
}
114150

@@ -280,7 +316,7 @@ func TestConfigList(t *testing.T) {
280316
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
281317
}
282318

283-
actual, err := List(drycc, "example-go")
319+
actual, err := List(drycc, "example-go", -1)
284320

285321
if err != nil {
286322
t.Error(err)
@@ -289,4 +325,16 @@ func TestConfigList(t *testing.T) {
289325
if !reflect.DeepEqual(expected, actual) {
290326
t.Errorf("Expected %v, Got %v", expected, actual)
291327
}
328+
329+
actual, err = List(drycc, "example-go", 2)
330+
if err != nil {
331+
t.Error(err)
332+
}
333+
if version, ok := actual.Values["VERSION"]; ok {
334+
if !reflect.DeepEqual(version, "2") {
335+
t.Errorf("Expected %v, Got %v", "2", version)
336+
}
337+
} else {
338+
t.Errorf("version not found %v", actual)
339+
}
292340
}

0 commit comments

Comments
 (0)