diff --git a/pagerduty/event_orchestration_path.go b/pagerduty/event_orchestration_path.go index 2ca243d..42bd643 100644 --- a/pagerduty/event_orchestration_path.go +++ b/pagerduty/event_orchestration_path.go @@ -176,7 +176,6 @@ func (s *EventOrchestrationPathService) Update(id string, pathType string, orche func (s *EventOrchestrationPathService) UpdateContext(ctx context.Context, id string, pathType string, orchestrationPath *EventOrchestrationPath) (*EventOrchestrationPathPayload, *Response, error) { u := orchestrationPathUrlBuilder(id, pathType) v := new(EventOrchestrationPathPayload) - sanitizeOrchestrationPath(orchestrationPath) p := EventOrchestrationPathPayload{OrchestrationPath: orchestrationPath} resp, err := s.client.newRequestDoContext(ctx, "PUT", u, nil, p, &v) @@ -187,42 +186,6 @@ func (s *EventOrchestrationPathService) UpdateContext(ctx context.Context, id st return v, resp, nil } -// Sanitize the conditions and actions to ensure that the arrays are not null -func sanitizeOrchestrationPath(servicePath *EventOrchestrationPath) { - for _, set := range servicePath.Sets { - for _, rule := range set.Rules { - if rule.Conditions == nil { - rule.Conditions = []*EventOrchestrationPathRuleCondition{} - } - if rule.Actions != nil { - sanitizeActions(rule.Actions) - } - } - } - if (servicePath.CatchAll != nil) { - sanitizeActions(servicePath.CatchAll.Actions) - } -} - -// Sanitize the actions to ensure that the arrays are not null -func sanitizeActions(actions *EventOrchestrationPathRuleActions) { - if actions.IncidentCustomFieldUpdates == nil { - actions.IncidentCustomFieldUpdates = []*EventOrchestrationPathIncidentCustomFieldUpdate{} - } - if actions.AutomationActions == nil { - actions.AutomationActions = []*EventOrchestrationPathAutomationAction{} - } - if actions.PagerdutyAutomationActions == nil { - actions.PagerdutyAutomationActions = []*EventOrchestrationPathPagerdutyAutomationAction{} - } - if actions.Variables == nil { - actions.Variables = []*EventOrchestrationPathActionVariables{} - } - if actions.Extractions == nil { - actions.Extractions = []*EventOrchestrationPathActionExtractions{} - } -} - // UpdateServiceActiveStatus for EventOrchestrationPath func (s *EventOrchestrationPathService) UpdateServiceActiveStatusContext(ctx context.Context, id string, isActive bool) (*EventOrchestrationPathServiceActiveStatus, *Response, error) { u := fmt.Sprintf("%s/services/%s/active", eventOrchestrationBaseUrl, id) diff --git a/pagerduty/event_orchestration_path_test.go b/pagerduty/event_orchestration_path_test.go index d03109b..096dc6e 100644 --- a/pagerduty/event_orchestration_path_test.go +++ b/pagerduty/event_orchestration_path_test.go @@ -250,55 +250,6 @@ func TestEventOrchestrationPathGetServiceActiveStatus(t *testing.T) { } } -func TestEventOrchestationSanitization(t *testing.T) { - setup() - defer teardown() - - input := &EventOrchestrationPath{ - Sets: []*EventOrchestrationPathSet{ - { - ID: "start", - Rules: []*EventOrchestrationPathRule{ - { - Actions: &EventOrchestrationPathRuleActions{}, - }, - }, - }, - }, - } - - var url = fmt.Sprintf("%s/E-ORC-1/global", eventOrchestrationBaseUrl) - - mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PUT") - v := new(EventOrchestrationPathPayload) - json.NewDecoder(r.Body).Decode(v) - if !reflect.DeepEqual(v.OrchestrationPath, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - w.Write([]byte(`{}`)) - }) - - // empty arrays are null by default - actionJson, _ := json.Marshal(input.Sets[0].Rules[0].Actions.PagerdutyAutomationActions) - want := "null" - if !reflect.DeepEqual(string(actionJson), want) { - t.Errorf("returned \n\n%#v want \n\n%#v", string(actionJson), want) - } - reflect.DeepEqual(actionJson, nil) - _, _, err := client.EventOrchestrationPaths.Update("E-ORC-1", PathTypeGlobal, input) - if err != nil { - t.Fatal(err) - } - // after sanitize, empty arrays are no longer null - actionJson, _ = json.Marshal(input.Sets[0].Rules[0].Actions.PagerdutyAutomationActions) - want = "[]" - if !reflect.DeepEqual(string(actionJson), want) { - t.Errorf("returned \n\n%#v want \n\n%#v", string(actionJson), want) - } - -} - func TestEventOrchestrationPathGlobalUpdate(t *testing.T) { setup() defer teardown() @@ -424,10 +375,6 @@ func TestEventOrchestrationPathGlobalUpdate(t *testing.T) { if !reflect.DeepEqual(v.OrchestrationPath, input) { t.Errorf("Request body = %+v, want %+v", v, input) } - actionJson, _ := json.Marshal(input.Sets[0].Rules[0].Actions.IncidentCustomFieldUpdates) - if !reflect.DeepEqual(string(actionJson), "[]") { - t.Errorf("empty action array should be []") - } w.Write([]byte(`{ "orchestration_path": { "catch_all": {"actions": {"suppress": true}}, @@ -542,9 +489,6 @@ func TestEventOrchestrationPathGlobalUpdate(t *testing.T) { }, } - // Before comparison, we sanitize the response to make it match the already sanitized request - sanitizeOrchestrationPath(resp.OrchestrationPath) - if !reflect.DeepEqual(resp, want) { t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) }