Skip to content

Commit

Permalink
Merge pull request #2 from theseion/add-overrides-schema
Browse files Browse the repository at this point in the history
feat: add schema for test overrides
  • Loading branch information
fzipi authored Feb 5, 2024
2 parents 93e883a + db67df0 commit c334dae
Show file tree
Hide file tree
Showing 16 changed files with 2,574 additions and 285 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# vendor/

# Generated files
types/types_doc.go
**/*_doc.go
16 changes: 13 additions & 3 deletions cmd/generate-doc-yaml-schema/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
// Copyright 2023 Felipe Zipitria
// Copyright 2023 OWASP CRS
// SPDX-License-Identifier: Apache-2.0

package main

import (
"os"

"github.com/coreruleset/ftw-tests-schema/types"
overrides "github.com/coreruleset/ftw-tests-schema/types/overrides"
test "github.com/coreruleset/ftw-tests-schema/types/test"
)

func main() {
data, err := types.GetFTWTestDoc().Encode()
data, err := test.GetFTWTestDoc().Encode()
if err != nil {
panic(err)
}
_, err = os.Stdout.Write(data)
if err != nil {
panic(err)
}

data, err = overrides.GetFTWOverridesDoc().Encode()
if err != nil {
panic(err)
}
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ go 1.21

require github.com/magefile/mage v1.15.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)

require (
// Goccy verion is expected to stay at 1.9.2 (Same of go-ftw) because of https://github.com/goccy/go-yaml/issues/325
github.com/goccy/go-yaml v1.9.2
Expand All @@ -14,6 +19,7 @@ require (
github.com/fatih/color v1.10.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/projectdiscovery/yamldoc-go v1.0.4 h1:eZoESapnMw6WAHiVgRwNqvbJEfNHEH1
github.com/projectdiscovery/yamldoc-go v1.0.4/go.mod h1:8PIPRcUD55UbtQdcfFR1hpIGRWG0P7alClXNGt1TBik=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
2 changes: 1 addition & 1 deletion mage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
// Copyright 2023 CRS
// SPDX-License-Identifier: Apache-2.0

//go:build ignore
Expand Down
25 changes: 17 additions & 8 deletions magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Felipe Zipitria
// Copyright 2023 CRS
// SPDX-License-Identifier: Apache-2.0

//go:build mage
Expand All @@ -16,18 +16,24 @@ import (
)

var addLicenseVersion = "v1.1.1" // https://github.com/google/addlicense
var golangCILintVer = "v1.55.1" // https://github.com/golangci/golangci-lint/releases
var golangCILintVer = "v1.55.2" // https://github.com/golangci/golangci-lint/releases
var gosImportsVer = "v0.3.8" // https://github.com/rinchsan/gosimports/releases/tag/v0.3.8

var errRunGoModTidy = errors.New("go.mod/sum not formatted, commit changes")
var errNoGitDir = errors.New("no .git directory found")
var errUpdateGeneratedFiles = errors.New("generated files need to be updated")

// Format formats code in this repository.
func Format() error {
// Generate Go documernation files for YAML structures
func Generate() error {
if err := sh.RunV("go", "generate", "./..."); err != nil {
return err
}
return nil
}

// Format formats code in this repository.
func Format() error {
mg.SerialDeps(Generate)

if err := sh.RunV("go", "mod", "tidy"); err != nil {
return err
Expand All @@ -36,7 +42,7 @@ func Format() error {
// addlicense strangely logs skipped files to stderr despite not being erroneous, so use the long sh.Exec form to
// discard stderr too.
if _, err := sh.Exec(map[string]string{}, io.Discard, io.Discard, "go", "run", fmt.Sprintf("github.com/google/addlicense@%s", addLicenseVersion),
"-c", "Felipe Zipitria",
"-c", "OWASP CRS",
"-s=only",
"-ignore", "**/*.yml",
"-ignore", "**/*.yaml",
Expand All @@ -52,9 +58,7 @@ func Format() error {

// Lint verifies code quality.
func Lint() error {
if err := sh.RunV("go", "generate", "./..."); err != nil {
return err
}
mg.SerialDeps(Generate)

if sh.Run("git", "diff", "--exit-code", "--", "'*_doc.go'") != nil {
return errUpdateGeneratedFiles
Expand All @@ -77,14 +81,19 @@ func Lint() error {

// Test runs all tests.
func Test() error {
mg.SerialDeps(Generate)

if err := sh.RunV("go", "test", "./..."); err != nil {
return err
}

return nil
}

// Generate Markdown output (printed to terminal)
func Markdown() error {
mg.SerialDeps(Generate)

if err := sh.RunV("go", "build", "./cmd/generate-doc-yaml-schema"); err != nil {
return err
}
Expand Down
Loading

0 comments on commit c334dae

Please sign in to comment.