Skip to content

Commit

Permalink
[testing] Add matrix, openapi and exported fields tests for BE (#7633)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Mitrofanov <nikolay.mitrofanov@flant.com>
  • Loading branch information
name212 authored Feb 26, 2024
1 parent 9b24528 commit e73e0f4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 15 deletions.
39 changes: 34 additions & 5 deletions testing/hooks/validation/exported_struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

// Check that structures which are used by FilterFunc don't have unexported fields
Expand Down Expand Up @@ -62,13 +63,41 @@ type structCheckResult struct {
Line int
}

type edition struct {
Name string `yaml:"name,omitempty"`
ModulesDir string `yaml:"modulesDir,omitempty"`
}

type editions struct {
Editions []edition `yaml:"editions,omitempty"`
}

func getPossiblePathToModules() []string {
content, err := os.ReadFile("/deckhouse/editions.yaml")
if err != nil {
panic(fmt.Sprintf("cannot read editions file: %v", err))
}

e := editions{}
err = yaml.Unmarshal(content, &e)
if err != nil {
panic(fmt.Errorf("cannot unmarshal editions file: %v", err))
}

modulesDir := make([]string, 0)
for i, ed := range e.Editions {
if ed.Name == "" {
panic(fmt.Sprintf("name for %d index is empty", i))
}
modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s/*/hooks", ed.ModulesDir))
}

return modulesDir
}

func collectGoHooks() []string {
var hookDirs []string
for _, possibleDir := range []string{
"/deckhouse/modules/*/hooks",
"/deckhouse/ee/modules/*/hooks",
"/deckhouse/ee/fe/modules/*/hooks",
} {
for _, possibleDir := range getPossiblePathToModules() {
result, err := filepath.Glob(possibleDir)
if err != nil {

Expand Down
38 changes: 33 additions & 5 deletions testing/matrix/linter/rules/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,43 @@ func helmignoreModuleRule(name, path string) errors.LintRuleError {
return errors.EmptyRuleError
}

type edition struct {
Name string `yaml:"name,omitempty"`
ModulesDir string `yaml:"modulesDir,omitempty"`
}

type editions struct {
Editions []edition `yaml:"editions,omitempty"`
}

func getPossiblePathToModules() []string {
content, err := os.ReadFile("/deckhouse/editions.yaml")
if err != nil {
panic(fmt.Sprintf("cannot read editions file: %v", err))
}

e := editions{}
err = yaml.Unmarshal(content, &e)
if err != nil {
panic(fmt.Errorf("cannot unmarshal editions file: %v", err))
}

modulesDir := make([]string, 0)
for i, ed := range e.Editions {
if ed.Name == "" {
panic(fmt.Sprintf("name for %d index is empty", i))
}
modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s", ed.ModulesDir))
}

return modulesDir
}

func GetDeckhouseModulesWithValuesMatrixTests(focusNames set.Set) (modules []utils.Module, err error) {
var possibleModulesPaths []string
modulesDir, ok := os.LookupEnv("MODULES_DIR")
if !ok {
possibleModulesPaths = []string{
"/deckhouse/modules",
"/deckhouse/ee/modules",
"/deckhouse/ee/fe/modules",
}
possibleModulesPaths = getPossiblePathToModules()
} else {
possibleModulesPaths = strings.Split(modulesDir, ":")
}
Expand Down
38 changes: 33 additions & 5 deletions testing/openapi_cases/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,45 @@ func (t *TestCases) HaveHelmValuesCases() bool {
return len(t.Positive.HelmValues) > 0 || len(t.Negative.HelmValues) > 0
}

type edition struct {
Name string `yaml:"name,omitempty"`
ModulesDir string `yaml:"modulesDir,omitempty"`
}

type editions struct {
Editions []edition `yaml:"editions,omitempty"`
}

func getPossiblePathToModules() []string {
content, err := os.ReadFile("/deckhouse/editions.yaml")
if err != nil {
panic(fmt.Sprintf("cannot read editions file: %v", err))
}

e := editions{}
err = yaml.Unmarshal(content, &e)
if err != nil {
panic(fmt.Errorf("cannot unmarshal editions file: %v", err))
}

modulesDir := make([]string, 0)
for i, ed := range e.Editions {
if ed.Name == "" {
panic(fmt.Sprintf("name for %d index is empty", i))
}
modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s/*/openapi", ed.ModulesDir))
}

return modulesDir
}

func GetAllOpenAPIDirs() ([]string, error) {
var (
dirs []string
openAPIDirs []string
)

for _, possibleDir := range []string{
"/deckhouse/modules/*/openapi",
"/deckhouse/ee/modules/*/openapi",
"/deckhouse/ee/fe/modules/*/openapi",
} {
for _, possibleDir := range getPossiblePathToModules() {
globDirs, err := filepath.Glob(possibleDir)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions werf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ git:
- testing
- go.mod
- go.sum
- editions.yaml
excludePaths:
{{ .Files.Get (printf "tools/build_includes/modules-excluded-%s.yaml" .Env) | nindent 2}}
- docs
Expand Down

0 comments on commit e73e0f4

Please sign in to comment.