Skip to content

Commit

Permalink
add CodeIssueCheck structs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Oct 24, 2024
1 parent f04970c commit ae62e1b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 42 deletions.
6 changes: 3 additions & 3 deletions check_code_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package opslevel

type CodeIssueCheckFragment struct {
Constraint CheckCodeIssueConstraintEnum `graphql:"constraint"` // The type of constraint used in evaluation the code issues check.
IssueName string `graphql:"issueName"` // The issue name used for code issue lookup.
IssueName *string `graphql:"issueName"` // The issue name used for code issue lookup.
IssueType []string `graphql:"issueType"` // The type of code issue to consider.
MaxAllowed int `graphql:"maxAllowed"` // The threshold count of code issues beyond which the check starts failing.
ResolutionTime CodeIssueResolutionTime `graphql:"resolutionTime"` // The resolution time recommended by the reporting source of the code issue.
MaxAllowed *int `graphql:"maxAllowed"` // The threshold count of code issues beyond which the check starts failing.
ResolutionTime *CodeIssueResolutionTime `graphql:"resolutionTime"` // The resolution time recommended by the reporting source of the code issue.
Severity []string `graphql:"severity"` // The severity levels of the issue.
}

Expand Down
73 changes: 50 additions & 23 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,68 +284,95 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
}),
},

"CreateCodeIssue": {
"CreateCodeIssueConstraintExact": {
fixture: BuildCreateRequest("CodeIssue", map[string]any{
"constraint": "exact",
"constraint": ol.CheckCodeIssueConstraintEnumExact,
"issueName": "test-issue",
"issueType": []string{"bug", "error"},
"maxAllowed": 3,
"resolutionTime": map[string]any{"unit": "day", "value": 1},
"severity": []string{"sev1", "sev2"},
}),
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckCreateInputTypeOf[ol.CheckCodeIssueCreateInput](checkCreateInput)
input.Constraint = ol.CheckCodeIssueConstraintEnumExact
input.IssueName = ol.RefOf("test-issue")
input.IssueType = ol.RefOf([]string{"bug", "error"})
input.MaxAllowed = ol.RefOf(3)
input.IssueType = nil // API NOTE - not allowed when constraint is "exact"
input.MaxAllowed = nil // API NOTE - not allowed when constraint is "exact"
input.ResolutionTime = ol.RefOf(ol.CodeIssueResolutionTimeInput{
Unit: ol.CodeIssueResolutionTimeUnitEnumDay,
Value: 1,
})
input.Severity = ol.RefOf([]string{"sev1", "sev2"})
input.Severity = nil // API NOTE - not allowed when constraint is "exact"
return c.CreateCheckCodeIssue(*input)
},
expectedCheck: CheckWithExtras(map[string]any{
"constraint": "exact",
"constraint": ol.CheckCodeIssueConstraintEnumExact,
"issueName": "test-issue",
"issueType": []string{"bug", "error"},
"maxAllowed": 3,
"issueType": nil,
"maxAllowed": nil,
"resolutionTime": map[string]any{"unit": "day", "value": 1},
"severity": []string{"sev1", "sev2"},
"severity": nil,
}),
},
"UpdateCodeIssue": {
"UpdateCodeIssueConstraintAny": {
fixture: BuildUpdateRequest("CodeIssue", map[string]any{
"constraint": "contains",
"issueName": "test-issue-updated",
"constraint": ol.CheckCodeIssueConstraintEnumAny,
"issueType": []string{"big-bug", "big-error"},
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": []string{"sev1"},
}),
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckCodeIssueUpdateInput](checkUpdateInput)
input.Constraint = ol.CheckCodeIssueConstraintEnumContains
input.IssueName = ol.RefOf("test-issue-updated")
input.IssueType = ol.RefOf([]string{"big-bug", "big-error"})
input.MaxAllowed = ol.RefOf(1)
input.ResolutionTime = ol.RefOf(ol.CodeIssueResolutionTimeInput{
input.Constraint = ol.CheckCodeIssueConstraintEnumAny
input.IssueName = nil // API NOTE - not allowed when constraint is "any"
input.IssueType = ol.NewNullableFrom([]string{"big-bug", "big-error"})
input.MaxAllowed = ol.NewNullableFrom(1)
input.ResolutionTime = ol.NewNullableFrom(ol.CodeIssueResolutionTimeInput{
Unit: ol.CodeIssueResolutionTimeUnitEnumWeek,
Value: 1,
})
input.Severity = ol.RefOf([]string{"sev1"})
input.Severity = ol.NewNullableFrom([]string{"sev1"})
return c.UpdateCheckCodeIssue(*input)
},
expectedCheck: CheckWithExtras(map[string]any{
"constraint": "contains",
"issueName": "test-issue-updated",
"constraint": ol.CheckCodeIssueConstraintEnumAny,
"issueName": nil,
"issueType": []string{"big-bug", "big-error"},
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": []string{"sev1"},
}),
},
"UpdateCodeIssueConstraintContains": {
fixture: BuildUpdateRequest("CodeIssue", map[string]any{
"constraint": ol.CheckCodeIssueConstraintEnumContains,
"issueName": "code-issue-updated",
"issueType": nil, // API NOTE - not allowed when constraint is "contains"
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": nil, // API NOTE - not allowed when constraint is "contains"
}),
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckCodeIssueUpdateInput](checkUpdateInput)
input.Constraint = ol.CheckCodeIssueConstraintEnumContains
input.IssueName = ol.RefOf("code-issue-updated")
input.IssueType = ol.NewNullOf[[]string]()
input.MaxAllowed = ol.NewNullableFrom(1)
input.ResolutionTime = ol.NewNullableFrom(ol.CodeIssueResolutionTimeInput{
Unit: ol.CodeIssueResolutionTimeUnitEnumWeek,
Value: 1,
})
input.Severity = ol.NewNullOf[[]string]()
return c.UpdateCheckCodeIssue(*input)
},
expectedCheck: CheckWithExtras(map[string]any{
"constraint": ol.CheckCodeIssueConstraintEnumContains,
"issueName": "code-issue-updated",
"issueType": nil,
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": nil,
}),
},

"CreateGitBranchProtection": {
fixture: BuildCreateRequest("GitBranchProtection", map[string]any{}),
Expand Down
30 changes: 15 additions & 15 deletions input.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func IsID(value string) bool {

// NullableConstraint defines what types can be nullable - keep separated using the union operator (pipe)
type NullableConstraint interface {
~string
any
}

// Nullable can be used to unset a value using an OpsLevel input struct type, should always be instantiated using a constructor.
Expand Down

0 comments on commit ae62e1b

Please sign in to comment.