[#6] Add new 'tests' command
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
b08b08d6a0
commit
8e325c79e5
6 changed files with 562 additions and 467 deletions
75
cmd/parser/modules/tests.go
Normal file
75
cmd/parser/modules/tests.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"sort"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/s3-tests-parser/internal/s3"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var testsCmd = &cobra.Command{
|
||||
Use: "tests",
|
||||
Short: "Print tests to check",
|
||||
Long: "Print all tests that will be checked by 'compatibility' command",
|
||||
Example: `s3-tests-parser tests
|
||||
s3-tests-parser tests --output tests.txt`,
|
||||
RunE: runTestsCmd,
|
||||
}
|
||||
|
||||
func initTestsCmd() {
|
||||
testsCmd.Flags().String(outputFlag, "", "file to write output, if missed the stdout is used")
|
||||
}
|
||||
|
||||
func runTestsCmd(cmd *cobra.Command, _ []string) error {
|
||||
testStruct, err := s3.ParseTestsStruct()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tests []string
|
||||
|
||||
groupTests := make(map[string][]string)
|
||||
for _, group := range testStruct.Groups {
|
||||
groupTests[group.Name] = group.Tests
|
||||
}
|
||||
|
||||
for _, group := range testStruct.Groups {
|
||||
if group.Skip {
|
||||
continue
|
||||
}
|
||||
|
||||
tests = append(tests, group.Tests...)
|
||||
for _, include := range group.Include {
|
||||
tests = append(tests, groupTests[include]...)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(tests)
|
||||
tests = slices.Compact(tests)
|
||||
|
||||
return printTests(cmd, tests)
|
||||
}
|
||||
|
||||
func printTests(cmd *cobra.Command, res []string) error {
|
||||
w := cmd.OutOrStdout()
|
||||
if outFile := viper.GetString(outputFlag); outFile != "" {
|
||||
f, err := os.Create(outFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create out file: %w", err)
|
||||
}
|
||||
w = f
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
for i := range res {
|
||||
if _, err := fmt.Fprintln(w, res[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue