package mocks import ( "encoding/json" "strings" "edge-infra.dev/pkg/edge/api/graph/model" ) type CreateOperatorInterventionCommandResponse struct { CreateOperatorInterventionCommand model.CreateOperatorInterventionCommandResponse `json:"createOperatorInterventionCommands"` } func CreateOperatorInterventionCommand(body []byte) (interface{}, bool, error) { if !strings.Contains(string(body), "createOperatorInterventionCommands(commands: $commands){errors{type,command,privilege,role}}") { return nil, false, nil } return CreateOperatorInterventionCommandResponse{}, true, nil } type CreateOperatorInterventionPrivilegeResponse struct { CreateOperatorInterventionPrivilege model.CreateOperatorInterventionPrivilegeResponse `json:"createOperatorInterventionPrivileges"` } func CreateOperatorInterventionPrivilege(body []byte) (interface{}, bool, error) { if !strings.Contains(string(body), "createOperatorInterventionPrivileges(privileges: $privileges){errors{type,command,privilege,role}}") { return nil, false, nil } return CreateOperatorInterventionPrivilegeResponse{}, true, nil } type UpdateOperatorInterventionRuleResponse struct { UpdateOperatorInterventionRule model.UpdateOperatorInterventionRuleResponse `json:"updateOperatorInterventionRules"` } func UpdateOperatorInterventionRule(body []byte) (interface{}, bool, error) { if !strings.Contains(string(body), "updateOperatorInterventionRules(rules: $rules){errors{type,command,privilege,role}}") { return UpdateOperatorInterventionRuleResponse{}, false, nil } var m struct { Query string Variables struct { Rules []struct { Privilege struct { Name string } Commands []*struct { Name string } } } } err := json.Unmarshal(body, &m) if err != nil { return UpdateOperatorInterventionRuleResponse{}, true, err } var resp UpdateOperatorInterventionRuleResponse // No need to map out all the different types of error. We only need to mock *an* error return. privilege := m.Variables.Rules[0].Privilege.Name if privilege == "unknown-privilege" { resp.UpdateOperatorInterventionRule.Errors = append(resp.UpdateOperatorInterventionRule.Errors, &model.OperatorInterventionErrorResponse{ Type: model.OperatorInterventionErrorTypeUnknownPrivilege, Privilege: &privilege, }) } return resp, true, nil } type UpdateOperatorInterventionRoleMappingResponse struct { UpdateOperatorInterventionRoleMapping model.UpdateOperatorInterventionRoleMappingResponse `json:"updateOperatorInterventionRoleMappings"` } func UpdateOperatorInterventionRoleMapping(body []byte) (interface{}, bool, error) { if !strings.Contains(string(body), "updateOperatorInterventionRoleMappings(roleMappings: $roleMappings){errors{type,command,privilege,role}}") { return nil, false, nil } var m struct { Query string Variables struct { RoleMappings []struct { Role string Privileges []struct { Name string } } } } err := json.Unmarshal(body, &m) if err != nil { return UpdateOperatorInterventionRoleMappingResponse{}, true, err } var resp UpdateOperatorInterventionRoleMappingResponse // No need to map out all the different types of error. We only need to mock *an* error return. if role := m.Variables.RoleMappings[0].Role; role == "unknown-role" { resp.UpdateOperatorInterventionRoleMapping.Errors = append(resp.UpdateOperatorInterventionRoleMapping.Errors, &model.OperatorInterventionErrorResponse{ Type: model.OperatorInterventionErrorTypeUnknownRole, Role: &role, }) } return resp, true, nil }