Skip to content

Commit

Permalink
chore: add more QA tests (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
loicbourgois authored Mar 11, 2020
1 parent a5c017d commit 86a8ca4
Showing 1 changed file with 59 additions and 10 deletions.
69 changes: 59 additions & 10 deletions internal/qa/qa.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package qa

import (
"strconv"
"strings"

"github.com/scaleway/scaleway-cli/internal/core"
Expand All @@ -10,6 +11,8 @@ func LintCommands(commands *core.Commands) []interface{} {
errors := []interface{}(nil)
errors = append(errors, testShortEndWithDotError(commands)...)
errors = append(errors, testShortIsNotPresentError(commands)...)
errors = append(errors, testArgMustUseDashError(commands)...)
errors = append(errors, testExampleCanHaveOnlyOneTypeOfExampleError(commands)...)
return errors
}

Expand All @@ -24,12 +27,11 @@ func (err ShortMustNotEndWithDotError) Error() string {
func testShortEndWithDotError(commands *core.Commands) []interface{} {
errors := []interface{}(nil)
for _, command := range commands.GetAll() {
if !strings.HasSuffix(command.Short, ".") {
continue
if strings.HasSuffix(command.Short, ".") {
errors = append(errors, &ShortMustNotEndWithDotError{
Command: command,
})
}
errors = append(errors, &ShortMustNotEndWithDotError{
Command: command,
})
}
return errors
}
Expand All @@ -45,12 +47,59 @@ func (err ShortMustBePresentError) Error() string {
func testShortIsNotPresentError(commands *core.Commands) []interface{} {
errors := []interface{}(nil)
for _, command := range commands.GetAll() {
if command.Short != "" {
continue
if command.Short == "" {
errors = append(errors, &ShortMustBePresentError{
Command: command,
})
}
}
return errors
}

type ArgMustUseDashError struct {
Command *core.Command
Argspec *core.ArgSpec
}

func (err ArgMustUseDashError) Error() string {
return "arg must use dash for command '" + err.Command.GetCommandLine() + "', arg '" + err.Argspec.Name + "'"
}

func testArgMustUseDashError(commands *core.Commands) []interface{} {
errors := []interface{}(nil)
for _, command := range commands.GetAll() {
for _, argspec := range command.ArgSpecs {
if strings.Contains(argspec.Name, "_") {
errors = append(errors, &ArgMustUseDashError{
Command: command,
Argspec: argspec,
})
}
}
}
return errors
}

type ExampleCanHaveOnlyOneTypeOfExampleError struct {
Command *core.Command
ExampleIndex int
}

func (err ExampleCanHaveOnlyOneTypeOfExampleError) Error() string {
return "arg must use dash for command '" + err.Command.GetCommandLine() + "', example #" + strconv.Itoa(err.ExampleIndex)
}

func testExampleCanHaveOnlyOneTypeOfExampleError(commands *core.Commands) []interface{} {
errors := []interface{}(nil)
for _, command := range commands.GetAll() {
for i, example := range command.Examples {
if example.Request != "" && example.Raw != "" {
errors = append(errors, &ExampleCanHaveOnlyOneTypeOfExampleError{
Command: command,
ExampleIndex: i,
})
}
}
errors = append(errors, &ShortMustBePresentError{
Command: command,
})
}
return errors
}

0 comments on commit 86a8ca4

Please sign in to comment.