forked from TrueCloudLab/s3-tests-parser
[#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
13
README.md
13
README.md
|
@ -21,3 +21,16 @@ You can also use json
|
|||
```shell
|
||||
$ ./bin/s3-tests-parser compatibility tests/fixture/suite.json --format json --output-format md --output result.md
|
||||
```
|
||||
|
||||
## Tests to check
|
||||
|
||||
You can see all tests that will be checked during `compatibility` command by using:
|
||||
```shell
|
||||
$ ./bin/s3-tests-parser tests --output tests.txt
|
||||
```
|
||||
|
||||
Output file now contains tests and can be provided as parameter for running [s3-tests](https://git.frostfs.info/TrueCloudLab/s3-tests):
|
||||
|
||||
```shell
|
||||
S3TEST_CONF=your.conf tox -- @tests.txt
|
||||
```
|
||||
|
|
|
@ -21,7 +21,8 @@ var compatibilityCmd = &cobra.Command{
|
|||
Example: `s3-tests-parser compatibility suite.csv
|
||||
s3-tests-parser compatibility suite.json --format json
|
||||
s3-tests-parser compatibility suite.json --format json --output-format md
|
||||
s3-tests-parser compatibility suite.json --format json --output-format md --output result.md`,
|
||||
s3-tests-parser compatibility suite.json --format json --output-format md --output result.md
|
||||
s3-tests-parser compatibility suite.json --format json --output-format txt --output result.txt --verbose`,
|
||||
RunE: runCompatibilityCmd,
|
||||
}
|
||||
|
||||
|
@ -149,10 +150,15 @@ func formTestResult(group s3.Group, testsMap map[string]bool) TestResult {
|
|||
var failed []string
|
||||
var passed []string
|
||||
for _, test := range group.Tests {
|
||||
if testsMap[test] {
|
||||
passed = append(passed, test)
|
||||
split := strings.Split(test, "::") // to trim test path
|
||||
if len(split) != 2 {
|
||||
continue
|
||||
}
|
||||
testName := split[1]
|
||||
if testsMap[testName] {
|
||||
passed = append(passed, testName)
|
||||
} else {
|
||||
failed = append(failed, test)
|
||||
failed = append(failed, testName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,4 +45,7 @@ GoVersion: {{ runtimeVersion }}
|
|||
|
||||
rootCmd.AddCommand(compatibilityCmd)
|
||||
initCompatibilityCmd()
|
||||
|
||||
rootCmd.AddCommand(testsCmd)
|
||||
initTestsCmd()
|
||||
}
|
||||
|
|
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
|
||||
}
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module git.frostfs.info/TrueCloudLab/s3-tests-parser
|
||||
|
||||
go 1.20
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v1.7.0
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue