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

add AffectsOverallServiceLevels field to Scorecard and ScorecardInput #282

Merged
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20231020-143907.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: add AffectsOverallServiceLevels field to Scorecard and ScorecardInput
time: 2023-10-20T14:39:07.227791-05:00
4 changes: 1 addition & 3 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ func NewString(value string) *string {
// Bool is a helper routine that allocates a new bool value
// to store v and returns a pointer to it.
func Bool(v bool) *bool {
p := new(bool)
*p = v
return p
return &v
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this change and the function in general, doesn't this have a different result than the comment above this function?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taimoor-at-opslevel So the problem is that you cannot do this

input := ScorecardInput{
  AffectsOverallServiceLevels: &true
}

So you have two ways to fix it - pass the bool value through a function to get it stored in a var and then return the address of the variable

input := ScorecardInput{
  AffectsOverallServiceLevels: ol.Bool(true)
}

OR make a local var and give the address

myBool := true
input := ScorecardInput{
  AffectsOverallServiceLevels: &myBool
}

Copy link
Collaborator

@rocktavious rocktavious Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the function was originally written was unnecessary - its creates an unneeded pointer - the way David fixed it is more idomatic go.

But you are right we should probably adjust the function docstring

}

func HandleErrors(err error, errs []OpsLevelErrors) error {
Expand Down
24 changes: 13 additions & 11 deletions scorecards.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ type ScorecardId struct {
type Scorecard struct {
ScorecardId

Description string `graphql:"description"` // optional
Filter Filter `graphql:"filter"` // optional
Name string `graphql:"name"`
Owner EntityOwner `graphql:"owner"`
PassingChecks int `graphql:"passingChecks"`
ServiceCount int `graphql:"serviceCount"`
ChecksCount int `graphql:"totalChecks"`
AffectsOverallServiceLevels bool `graphql:"affectsOverallServiceLevels"`
Description string `graphql:"description"` // optional
Filter Filter `graphql:"filter"` // optional
Name string `graphql:"name"`
Owner EntityOwner `graphql:"owner"`
PassingChecks int `graphql:"passingChecks"`
ServiceCount int `graphql:"serviceCount"`
ChecksCount int `graphql:"totalChecks"`
}

type ScorecardConnection struct {
Expand All @@ -28,10 +29,11 @@ type ScorecardConnection struct {
}

type ScorecardInput struct {
Name string `graphql:"name" json:"name"`
Description *string `graphql:"description" json:"description,omitempty"`
OwnerId ID `graphql:"ownerId" json:"ownerId"`
FilterId *ID `graphql:"filterId" json:"filterId,omitempty"`
AffectsOverallServiceLevels *bool `graphql:"affectsOverallServiceLevels" json:"affectsOverallServiceLevels,omitempty"`
Name string `graphql:"name" json:"name"`
Description *string `graphql:"description" json:"description,omitempty"`
OwnerId ID `graphql:"ownerId" json:"ownerId"`
FilterId *ID `graphql:"filterId" json:"filterId,omitempty"`
}

func (client *Client) CreateScorecard(input ScorecardInput) (*Scorecard, error) {
Expand Down
37 changes: 33 additions & 4 deletions scorecards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,45 @@ func TestCreateScorecard(t *testing.T) {

client := BestTestClient(t, "scorecards/create_scorecard", testRequest)
sc, err := client.CreateScorecard(ol.ScorecardInput{
Name: name,
Description: &description,
OwnerId: *fakeOwnerId,
FilterId: fakeFilterId,
Name: name,
Description: &description,
OwnerId: *fakeOwnerId,
FilterId: fakeFilterId,
AffectsOverallServiceLevels: ol.Bool(true),
})

autopilot.Ok(t, err)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *fakeOwnerId, sc.Owner.Id())
autopilot.Equals(t, *fakeFilterId, sc.Filter.Id)
autopilot.Equals(t, true, sc.AffectsOverallServiceLevels)
}

func TestCreateScorecardDoesNotAffectServiceLevels(t *testing.T) {
testRequest := NewTestRequest(
`{{ template "scorecard_create_request" }}`,
`{{ template "scorecard_create_request_vars_affects_service_levels_false" }}`,
`{{ template "scorecard_create_response_affects_service_levels_false" }}`,
)
name := "new scorecard"
description := "a new scorecard with an attached filter id"

client := BestTestClient(t, "scorecards/create_scorecard_not_affects_service_levels", testRequest)
sc, err := client.CreateScorecard(ol.ScorecardInput{
Name: name,
Description: &description,
OwnerId: *fakeOwnerId,
FilterId: fakeFilterId,
AffectsOverallServiceLevels: ol.Bool(false),
})

autopilot.Ok(t, err)
autopilot.Equals(t, name, sc.Name)
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *fakeOwnerId, sc.Owner.Id())
autopilot.Equals(t, *fakeFilterId, sc.Filter.Id)
autopilot.Equals(t, false, sc.AffectsOverallServiceLevels)
}

func TestUpdateScorecard(t *testing.T) {
Expand All @@ -63,6 +91,7 @@ func TestUpdateScorecard(t *testing.T) {
autopilot.Equals(t, description, sc.Description)
autopilot.Equals(t, *newOwnerId, sc.Owner.Id())
autopilot.Equals(t, *newFilterId, sc.Filter.Id)
autopilot.Equals(t, false, sc.AffectsOverallServiceLevels)
}

func TestDeleteScorecard(t *testing.T) {
Expand Down
20 changes: 14 additions & 6 deletions testdata/templates/scorecards.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
{{- define "scorecard_create_request" }}
"mutation ScorecardCreate($input:ScorecardInput!){scorecardCreate(input: $input){scorecard{aliases,id,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},errors{message,path}}}"
"mutation ScorecardCreate($input:ScorecardInput!){scorecardCreate(input: $input){scorecard{aliases,id,affectsOverallServiceLevels,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},errors{message,path}}}"
{{ end }}

{{- define "scorecard_create_request_vars" }}
{"input":{"description":"a new scorecard with an attached filter id","name":"new scorecard","ownerId":"Z2lkOi8vMTIzNDU2Nzg5Cg==","filterId":"Z2lkOi8vMTIzNDU2MTIzCg=="}}
{"input":{"affectsOverallServiceLevels":true,"description":"a new scorecard with an attached filter id","name":"new scorecard","ownerId":"Z2lkOi8vMTIzNDU2Nzg5Cg==","filterId":"Z2lkOi8vMTIzNDU2MTIzCg=="}}
{{ end }}

{{- define "scorecard_create_request_vars_affects_service_levels_false" }}
{"input":{"affectsOverallServiceLevels":false,"description":"a new scorecard with an attached filter id","name":"new scorecard","ownerId":"Z2lkOi8vMTIzNDU2Nzg5Cg==","filterId":"Z2lkOi8vMTIzNDU2MTIzCg=="}}
{{ end }}

{{- define "scorecard_create_response" }}{
"data":{"scorecardCreate":{"scorecard":{"description":"a new scorecard with an attached filter id","filter":{"connective":null,"htmlUrl":"https://app.opslevel.com/filters/123456123","id":"Z2lkOi8vMTIzNDU2MTIzCg==","name":"some filter","predicates":[]},"name":"new scorecard","owner":{"id":"Z2lkOi8vMTIzNDU2Nzg5Cg=="}},"errors":[]}}
"data":{"scorecardCreate":{"scorecard":{"affectsOverallServiceLevels":true,"description":"a new scorecard with an attached filter id","filter":{"connective":null,"htmlUrl":"https://app.opslevel.com/filters/123456123","id":"Z2lkOi8vMTIzNDU2MTIzCg==","name":"some filter","predicates":[]},"name":"new scorecard","owner":{"id":"Z2lkOi8vMTIzNDU2Nzg5Cg=="}},"errors":[]}}
}{{ end }}

{{- define "scorecard_create_response_affects_service_levels_false" }}{
"data":{"scorecardCreate":{"scorecard":{"affectsOverallServiceLevels":false,"description":"a new scorecard with an attached filter id","filter":{"connective":null,"htmlUrl":"https://app.opslevel.com/filters/123456123","id":"Z2lkOi8vMTIzNDU2MTIzCg==","name":"some filter","predicates":[]},"name":"new scorecard","owner":{"id":"Z2lkOi8vMTIzNDU2Nzg5Cg=="}},"errors":[]}}
}{{ end }}

{{- define "scorecard_update_request" }}
"mutation ScorecardUpdate($input:ScorecardInput!$scorecard:IdentifierInput!){scorecardUpdate(scorecard: $scorecard, input: $input){scorecard{aliases,id,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},errors{message,path}}}"
"mutation ScorecardUpdate($input:ScorecardInput!$scorecard:IdentifierInput!){scorecardUpdate(scorecard: $scorecard, input: $input){scorecard{aliases,id,affectsOverallServiceLevels,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},errors{message,path}}}"
{{ end }}

{{- define "scorecard_update_request_vars" }}
Expand All @@ -35,7 +43,7 @@
}{{ end }}

{{- define "scorecard_get_request" }}
"query ScorecardGet($input:IdentifierInput!){account{scorecard(input: $input){aliases,id,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks}}}"
"query ScorecardGet($input:IdentifierInput!){account{scorecard(input: $input){aliases,id,affectsOverallServiceLevels,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks}}}"
{{ end }}

{{- define "scorecard_get_request_vars" }}
Expand All @@ -46,7 +54,7 @@
"data":{"account":{"scorecard":{"aliases":["existing_scorecard"],"id":"Z2lkOi8vMTIzNDU2Nzg5MTAK","description":"hello there!","filter":{"connective":null,"htmlUrl":"https://app.opslevel.com/filters/123456123","id":"Z2lkOi8vMTIzNDU2MTIzCg==","name":"some filter","predicates":[]},"name":"fetched scorecard","owner":{"id":"Z2lkOi8vMTIzNDU2Nzg5Cg=="},"passingChecks":10,"serviceCount":20,"totalChecks":30}}}
}{{ end }}

{{- define "scorecard_list_query" }}query ScorecardsList($after:String!$first:Int!){account{scorecards(after: $after, first: $first){nodes{aliases,id,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}{{ end }}
{{- define "scorecard_list_query" }}query ScorecardsList($after:String!$first:Int!){account{scorecards(after: $after, first: $first){nodes{aliases,id,affectsOverallServiceLevels,description,filter{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},name,owner{... on Group{groupAlias:alias,id},... on Team{teamAlias:alias,id}},passingChecks,serviceCount,totalChecks},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}{{ end }}

{{- define "scorecard_1_response" }}
"id":"Z2lkOi8vMTExMTExMTEK",
Expand Down
Loading