-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/heimweh/go-pagerduty
- Loading branch information
Showing
22 changed files
with
2,114 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ dist: trusty | |
sudo: false | ||
language: go | ||
go: | ||
- "1.12.4" | ||
- "1.15.6" | ||
|
||
env: | ||
GO111MODULE=off | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package pagerduty | ||
|
||
import "fmt" | ||
|
||
// BusinessServiceService handles the communication with business service | ||
// related methods of the PagerDuty API. | ||
type BusinessServiceService service | ||
|
||
// BusinessService represents a business service. | ||
type BusinessService struct { | ||
ID string `json:"id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
Summary string `json:"summary,omitempty"` | ||
Self string `json:"self,omitempty"` | ||
PointOfContact string `json:"point_of_contact,omitempty"` | ||
HTMLUrl string `json:"html_url,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
Team *BusinessServiceTeam `json:"team,omitempty"` | ||
} | ||
|
||
// BusinessServiceTeam represents a team object in a business service | ||
type BusinessServiceTeam struct { | ||
ID string `json:"id,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
Self string `json:"self,omitempty"` | ||
} | ||
|
||
// BusinessServicePayload represents payload with a business service object | ||
type BusinessServicePayload struct { | ||
BusinessService *BusinessService `json:"business_service,omitempty"` | ||
} | ||
|
||
// ListBusinessServicesResponse represents a list response of business services. | ||
type ListBusinessServicesResponse struct { | ||
Total int `json:"total,omitempty"` | ||
BusinessServices []*BusinessService `json:"business_services,omitempty"` | ||
Offset int `json:"offset,omitempty"` | ||
More bool `json:"more,omitempty"` | ||
Limit int `json:"limit,omitempty"` | ||
} | ||
|
||
// List lists existing business services. | ||
func (s *BusinessServiceService) List() (*ListBusinessServicesResponse, *Response, error) { | ||
u := "/business_services" | ||
v := new(ListBusinessServicesResponse) | ||
|
||
resp, err := s.client.newRequestDo("GET", u, nil, nil, &v) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return v, resp, nil | ||
} | ||
|
||
// Create creates a new business service. | ||
func (s *BusinessServiceService) Create(ruleset *BusinessService) (*BusinessService, *Response, error) { | ||
u := "/business_services" | ||
v := new(BusinessServicePayload) | ||
p := &BusinessServicePayload{BusinessService: ruleset} | ||
|
||
resp, err := s.client.newRequestDo("POST", u, nil, p, v) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return v.BusinessService, resp, nil | ||
} | ||
|
||
// Get gets a business service. | ||
func (s *BusinessServiceService) Get(ID string) (*BusinessService, *Response, error) { | ||
u := fmt.Sprintf("/business_services/%s", ID) | ||
v := new(BusinessServicePayload) | ||
p := &BusinessServicePayload{} | ||
|
||
resp, err := s.client.newRequestDo("GET", u, nil, p, v) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return v.BusinessService, resp, nil | ||
} | ||
|
||
// Delete deletes a business service. | ||
func (s *BusinessServiceService) Delete(ID string) (*Response, error) { | ||
u := fmt.Sprintf("/business_services/%s", ID) | ||
return s.client.newRequestDo("DELETE", u, nil, nil, nil) | ||
} | ||
|
||
// Update updates a business service. | ||
func (s *BusinessServiceService) Update(ID string, ruleset *BusinessService) (*BusinessService, *Response, error) { | ||
u := fmt.Sprintf("/business_services/%s", ID) | ||
v := new(BusinessServicePayload) | ||
p := BusinessServicePayload{BusinessService: ruleset} | ||
|
||
resp, err := s.client.newRequestDo("PUT", u, nil, p, v) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return v.BusinessService, resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestBusinessServiceList(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/business_services", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
w.Write([]byte(`{"total": 1, "offset": 0, "more": false, "limit": 25, "business_services":[{"id": "1"}]}`)) | ||
}) | ||
|
||
resp, _, err := client.BusinessServices.List() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := &ListBusinessServicesResponse{ | ||
Total: 1, | ||
Offset: 0, | ||
More: false, | ||
Limit: 25, | ||
BusinessServices: []*BusinessService{ | ||
{ | ||
ID: "1", | ||
}, | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(resp, want) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) | ||
} | ||
} | ||
|
||
func TestBusinessServiceCreate(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
input := &BusinessService{Name: "foo"} | ||
|
||
mux.HandleFunc("/business_services", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "POST") | ||
v := new(BusinessService) | ||
v.Name = "foo" | ||
json.NewDecoder(r.Body).Decode(v) | ||
if !reflect.DeepEqual(v, input) { | ||
t.Errorf("Request body = %+v, want %+v", v, input) | ||
} | ||
w.Write([]byte(`{"business_service":{"name": "foo", "id":"1"}}`)) | ||
}) | ||
|
||
resp, _, err := client.BusinessServices.Create(input) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := &BusinessService{ | ||
Name: "foo", | ||
ID: "1", | ||
} | ||
|
||
if !reflect.DeepEqual(resp, want) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) | ||
} | ||
} | ||
func TestBusinessServiceGet(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/business_services/1", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
w.Write([]byte(`{"business_service":{"name": "foo", "id":"1"}}`)) | ||
}) | ||
|
||
ID := "1" | ||
resp, _, err := client.BusinessServices.Get(ID) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := &BusinessService{ | ||
Name: "foo", | ||
ID: "1", | ||
} | ||
|
||
if !reflect.DeepEqual(resp, want) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) | ||
} | ||
} | ||
|
||
func TestBusinessServiceUpdate(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
input := &BusinessService{ | ||
Name: "foo", | ||
} | ||
|
||
mux.HandleFunc("/business_services/1", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "PUT") | ||
v := new(BusinessService) | ||
v.Name = "foo" | ||
|
||
json.NewDecoder(r.Body).Decode(v) | ||
if !reflect.DeepEqual(v, input) { | ||
t.Errorf("Request body = %+v, want %+v", v, input) | ||
} | ||
w.Write([]byte(`{"business_service":{"name": "foo", "id":"1"}}`)) | ||
}) | ||
|
||
resp, _, err := client.BusinessServices.Update("1", input) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := &BusinessService{ | ||
Name: "foo", | ||
ID: "1", | ||
} | ||
|
||
if !reflect.DeepEqual(resp, want) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) | ||
} | ||
} | ||
|
||
func TestBusinessServiceDelete(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/business_services/1", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "DELETE") | ||
w.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
if _, err := client.BusinessServices.Delete("1"); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.