File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,13 +94,14 @@ func main() {
9494
9595 if err != nil || res .StatusCode != 200 {
9696 fmt .Println ("failed retrieving config from controller" )
97- fmt .Println ( body )
97+ fmt .Printf ( "%v \n " , body )
9898 os .Exit (1 )
9999 }
100100
101- config , err := builder .ParseConfig (res )
101+ config , err := builder .ParseConfig (body )
102102 if err != nil {
103103 fmt .Println ("failed parsing config from controller" )
104+ fmt .Printf ("%v\n " , err )
104105 os .Exit (1 )
105106 }
106107 toString , err := json .Marshal (config )
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package builder
33import (
44 "encoding/json"
55 "fmt"
6- "io/ioutil"
7- "net/http"
86
97 "gopkg.in/yaml.v2"
108)
@@ -27,15 +25,9 @@ func YamlToJSON(bytes []byte) (string, error) {
2725}
2826
2927// ParseConfig takes a response body from the controller and returns a Config object.
30- func ParseConfig (res * http.Response ) (* Config , error ) {
31- body , err := ioutil .ReadAll (res .Body )
32-
33- if err != nil {
34- return nil , err
35- }
36-
28+ func ParseConfig (body []byte ) (* Config , error ) {
3729 var config Config
38- err = json .Unmarshal (body , & config )
30+ err : = json .Unmarshal (body , & config )
3931 return & config , err
4032}
4133
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package builder
33import (
44 "bytes"
55 "encoding/json"
6- "net/http"
76 "strings"
87 "testing"
98 "time"
@@ -58,20 +57,17 @@ worker: while true; do echo hello; sleep 1; done`),
5857
5958func TestParseConfigGood (t * testing.T ) {
6059 // mock the controller response
61- resp := & http.Response {
62- Body : & ClosingBuffer {bytes .NewBufferString (`{"owner": "test",
60+ resp := bytes .NewBufferString (`{"owner": "test",
6361 "app": "example-go",
6462 "values": {"FOO": "bar", "CAR": 1234},
6563 "memory": {},
6664 "cpu": {},
6765 "tags": {},
6866 "created": "2014-01-01T00:00:00UTC",
6967 "updated": "2014-01-01T00:00:00UTC",
70- "uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"}` ),
71- },
72- }
68+ "uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"}` )
7369
74- config , err := ParseConfig (resp )
70+ config , err := ParseConfig (resp . Bytes () )
7571
7672 if err != nil {
7773 t .Error (err )
You can’t perform that action at this time.
0 commit comments