Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure consistent naming for ServiceID (fixes missed references) #249

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fastly/realtime_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type RealtimeData struct {

// GetRealtimeStatsInput is an input parameter to GetRealtimeStats function
type GetRealtimeStatsInput struct {
Service string
ServiceID string
Timestamp uint64
Limit uint32
}
Expand All @@ -47,11 +47,11 @@ func (c *RTSClient) GetRealtimeStats(i *GetRealtimeStatsInput) (*RealtimeStatsRe

// GetRealtimeStatsJSON fetches stats and decodes the response directly to the JSON struct dst.
func (c *RTSClient) GetRealtimeStatsJSON(i *GetRealtimeStatsInput, dst interface{}) error {
if i.Service == "" {
if i.ServiceID == "" {
return ErrMissingServiceID
}

path := fmt.Sprintf("/v1/channel/%s/ts/%d", i.Service, i.Timestamp)
path := fmt.Sprintf("/v1/channel/%s/ts/%d", i.ServiceID, i.Timestamp)

if i.Limit != 0 {
path = fmt.Sprintf("%s/limit/%d", path, i.Limit)
Expand Down
6 changes: 3 additions & 3 deletions fastly/realtime_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func TestClient_GetRealtimeStats_validation(t *testing.T) {
var err error
_, err = testStatsClient.GetRealtimeStats(&GetRealtimeStatsInput{
Service: "",
ServiceID: "",
})
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
Expand All @@ -22,7 +22,7 @@ func TestStatsClient_GetRealtimeStats(t *testing.T) {
// Get
recordRealtimeStats(t, "realtime_stats/get", func(c *RTSClient) {
_, err = c.GetRealtimeStats(&GetRealtimeStatsInput{
Service: testServiceID,
ServiceID: testServiceID,
Timestamp: 0,
Limit: 3,
})
Expand All @@ -42,7 +42,7 @@ func TestStatsClient_GetRealtimeStatsJSON(t *testing.T) {
var err error
recordRealtimeStats(t, "realtime_stats/get", func(c *RTSClient) {
err = c.GetRealtimeStatsJSON(&GetRealtimeStatsInput{
Service: testServiceID,
ServiceID: testServiceID,
Timestamp: 0,
Limit: 3,
}, &ret)
Expand Down
8 changes: 4 additions & 4 deletions fastly/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ func (c *Client) GetServiceDetails(i *GetServiceInput) (*ServiceDetail, error) {

// UpdateServiceInput is used as input to the UpdateService function.
type UpdateServiceInput struct {
ID string
ServiceID string

Name *string `form:"name,omitempty"`
Comment *string `form:"comment,omitempty"`
}

// UpdateService updates the service with the given input.
func (c *Client) UpdateService(i *UpdateServiceInput) (*Service, error) {
if i.ID == "" {
return nil, ErrMissingID
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}

if i.Name == nil && i.Comment == nil {
Expand All @@ -165,7 +165,7 @@ func (c *Client) UpdateService(i *UpdateServiceInput) (*Service, error) {
return nil, ErrMissingNameValue
}

path := fmt.Sprintf("/service/%s", i.ID)
path := fmt.Sprintf("/service/%s", i.ServiceID)
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions fastly/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func TestClient_Services(t *testing.T) {
var us *Service
record(t, "services/update", func(c *Client) {
us, err = c.UpdateService(&UpdateServiceInput{
ID: s.ID,
Name: String("new-test-service"),
ServiceID: s.ID,
Name: String("new-test-service"),
})
})
if err != nil {
Expand Down Expand Up @@ -171,20 +171,20 @@ func TestClient_GetService_validation(t *testing.T) {
func TestClient_UpdateService_validation(t *testing.T) {
var err error
_, err = testClient.UpdateService(&UpdateServiceInput{})
if err != ErrMissingID {
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
}

_, err = testClient.UpdateService(&UpdateServiceInput{
ID: "foo",
ServiceID: "foo",
})
if err != ErrMissingOptionalNameComment {
t.Errorf("bad error: %s", err)
}

_, err = testClient.UpdateService(&UpdateServiceInput{
ID: "foo",
Name: String(""),
ServiceID: "foo",
Name: String(""),
})
if err != ErrMissingNameValue {
t.Errorf("bad error: %s", err)
Expand Down