Skip to content

Commit

Permalink
Merge pull request #31 from go-chef/envresult
Browse files Browse the repository at this point in the history
Use EnvironmentResult vs CreateReault & ListResult
  • Loading branch information
bigkraig committed Aug 14, 2014
2 parents d929ec8 + b5d6b67 commit bcb9aea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
16 changes: 5 additions & 11 deletions environment.go
Expand Up @@ -8,8 +8,7 @@ type EnvironmentService struct {
client *Client
}

type EnvironmentListResult map[string]string
type EnvironmentCreateResult map[string]string
type EnvironmentResult map[string]string

// Environment represents the native Go version of the deserialized Environment type
type Environment struct {
Expand Down Expand Up @@ -38,28 +37,23 @@ func strMapToStr(e map[string]string) (out string) {
return
}

// String makes EnvironmentListResult implement the string result
func (e EnvironmentListResult) String() (out string) {
return strMapToStr(e)
}

// String makes EnvironmentCreateResult implement the string result
func (e EnvironmentCreateResult) String() (out string) {
// String makes EnvironmentResult implement the string result
func (e EnvironmentResult) String() (out string) {
return strMapToStr(e)
}

// List lists the environments in the Chef server.
//
// Chef API docs: http://docs.getchef.com/api_chef_server.html#id14
func (e *EnvironmentService) List() (data *EnvironmentListResult, err error) {
func (e *EnvironmentService) List() (data *EnvironmentResult, err error) {
err = e.client.magicRequestDecoder("GET", "environments", nil, &data)
return
}

// Create an environment in the Chef server.
//
// Chef API docs: http://docs.getchef.com/api_chef_server.html#id15
func (e *EnvironmentService) Create(environment *Environment) (data *EnvironmentCreateResult, err error) {
func (e *EnvironmentService) Create(environment *Environment) (data *EnvironmentResult, err error) {
body, err := JSONReader(environment)
if err != nil {
return
Expand Down
12 changes: 6 additions & 6 deletions environment_test.go
Expand Up @@ -44,7 +44,7 @@ func TestEnvironmentsService_List(t *testing.T) {
t.Errorf("Environments.List returned error: %v", err)
}

want := &EnvironmentListResult{"_default": "blah", "development": "blah"}
want := &EnvironmentResult{"_default": "blah", "development": "blah"}
if !reflect.DeepEqual(environments, want) {
//spew.Dump(environments)
//spew.Dump(want)
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestEnvironmentsService_Create(t *testing.T) {
t.Errorf("Environments.Create returned error: %v", err)
}

want := &EnvironmentCreateResult{"uri": "http://localhost:4000/environments/dev"}
want := &EnvironmentResult{"uri": "http://localhost:4000/environments/dev"}

if !reflect.DeepEqual(uri, want) {
t.Errorf("Environments.Create returned %+v, want %+v", uri, want)
Expand Down Expand Up @@ -142,17 +142,17 @@ func TestEnvironmentsService_Put(t *testing.T) {
}

func TestEnvironmentsService_EnvironmentListResultString(t *testing.T) {
e := &EnvironmentListResult{"_default": "https://api.opscode.com/organizations/org_name/environments/_default", "webserver": "https://api.opscode.com/organizations/org_name/environments/webserver"}
e := &EnvironmentResult{"_default": "https://api.opscode.com/organizations/org_name/environments/_default", "webserver": "https://api.opscode.com/organizations/org_name/environments/webserver"}
want := "_default => https://api.opscode.com/organizations/org_name/environments/_default\nwebserver => https://api.opscode.com/organizations/org_name/environments/webserver\n"
if e.String() != want {
t.Errorf("EnvironmentListResult.String returned:\n%+v\nwant:\n%+v\n", e.String(), want)
t.Errorf("EnvironmentResult.String returned:\n%+v\nwant:\n%+v\n", e.String(), want)
}
}

func TestEnvironmentsService_EnvironmentCreateResultString(t *testing.T) {
e := &EnvironmentCreateResult{"uri": "http://localhost:4000/environments/dev"}
e := &EnvironmentResult{"uri": "http://localhost:4000/environments/dev"}
want := "uri => http://localhost:4000/environments/dev\n"
if e.String() != want {
t.Errorf("EnvironmentCreateResult.String returned %+v, want %+v", e.String(), want)
t.Errorf("EnvironmentResult.String returned %+v, want %+v", e.String(), want)
}
}

0 comments on commit bcb9aea

Please sign in to comment.