2024-11-22 08:49:26 +00:00
|
|
|
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 {
|
2024-11-27 09:44:33 +00:00
|
|
|
if group.Skip {
|
|
|
|
continue
|
|
|
|
}
|
2024-11-22 08:49:26 +00:00
|
|
|
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
|
|
|
|
}
|