Skip to content

Commit

Permalink
Fix CI to not warn in unrelevant occasions
Browse files Browse the repository at this point in the history
  • Loading branch information
sunboyy committed May 21, 2024
1 parent c379f87 commit 6c4bc68
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude_patterns:
- "examples/"
- "**/*_test.go"
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 75%
target: 90%
patch:
default:
target: 80%
Expand Down
17 changes: 11 additions & 6 deletions internal/spec/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,20 @@ func (p queryParser) parseQuery(rawTokens []string, paramIndex int) (QuerySpec,
return QuerySpec{}, ErrQueryRequired
}

tokens := rawTokens
if len(tokens) == 1 && tokens[0] == "All" {
return QuerySpec{}, nil
switch rawTokens[0] {
case "All":
if len(rawTokens) == 1 {
return QuerySpec{}, nil
}
case "By":
return p.parseQueryBy(rawTokens, paramIndex)
}

if tokens[0] == "By" {
tokens = tokens[1:]
}
return QuerySpec{}, NewInvalidQueryError(rawTokens)

Check warning on line 100 in internal/spec/query.go

View check run for this annotation

Codecov / codecov/patch

internal/spec/query.go#L100

Added line #L100 was not covered by tests
}

func (p queryParser) parseQueryBy(rawTokens []string, paramIndex int) (QuerySpec, error) {
tokens := rawTokens[1:]
if len(tokens) == 0 {
return QuerySpec{}, NewInvalidQueryError(rawTokens)
}
Expand Down
47 changes: 32 additions & 15 deletions internal/spec/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ func (p interfaceMethodParser) parseUpdate(tokens []string) (Update, error) {
return UpdateModel{}, nil
}

updateFields, err := p.parseUpdateFieldsFromTokens(tokens)
if err != nil {
return nil, err
}

if err := p.validateUpdateFieldsWithParams(updateFields); err != nil {
return nil, err
}

return updateFields, nil
}

func (p interfaceMethodParser) parseUpdateFieldsFromTokens(tokens []string) (UpdateFields, error) {
updateFieldTokens, ok := splitByAnd(tokens)
if !ok {
return nil, ErrInvalidUpdateFields
Expand All @@ -142,21 +155,6 @@ func (p interfaceMethodParser) parseUpdate(tokens []string) (Update, error) {
paramIndex += updateField.Operator.NumberOfArguments()
}

for _, field := range updateFields {
if p.Signature.Params().Len() < field.ParamIndex+field.Operator.NumberOfArguments() {
return nil, ErrInvalidUpdateFields
}

expectedType := field.Operator.ArgumentType(field.FieldReference.ReferencedField().Var.Type())

for i := 0; i < field.Operator.NumberOfArguments(); i++ {
if !types.Identical(p.Signature.Params().At(field.ParamIndex+i).Type(), expectedType) {
return nil, NewArgumentTypeNotMatchedError(field.FieldReference.ReferencingCode(), expectedType,
p.Signature.Params().At(field.ParamIndex+i).Type())
}
}
}

return updateFields, nil
}

Expand Down Expand Up @@ -214,3 +212,22 @@ func (p interfaceMethodParser) validateUpdateOperator(referencedType types.Type,
}
return true
}

func (p interfaceMethodParser) validateUpdateFieldsWithParams(updateFields UpdateFields) error {
for _, field := range updateFields {
if p.Signature.Params().Len() < field.ParamIndex+field.Operator.NumberOfArguments() {
return ErrInvalidUpdateFields
}

expectedType := field.Operator.ArgumentType(field.FieldReference.ReferencedField().Var.Type())

for i := 0; i < field.Operator.NumberOfArguments(); i++ {
if !types.Identical(p.Signature.Params().At(field.ParamIndex+i).Type(), expectedType) {
return NewArgumentTypeNotMatchedError(field.FieldReference.ReferencingCode(), expectedType,
p.Signature.Params().At(field.ParamIndex+i).Type())
}
}
}

return nil
}

0 comments on commit 6c4bc68

Please sign in to comment.