Skip to content

Commit c334dae

Browse files
authored
Merge pull request #2 from theseion/add-overrides-schema
feat: add schema for test overrides
2 parents 93e883a + db67df0 commit c334dae

File tree

16 files changed

+2574
-285
lines changed

16 files changed

+2574
-285
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# vendor/
1616

1717
# Generated files
18-
types/types_doc.go
18+
**/*_doc.go

cmd/generate-doc-yaml-schema/main.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
// Copyright 2023 Felipe Zipitria
1+
// Copyright 2023 OWASP CRS
22
// SPDX-License-Identifier: Apache-2.0
33

44
package main
55

66
import (
77
"os"
88

9-
"github.com/coreruleset/ftw-tests-schema/types"
9+
overrides "github.com/coreruleset/ftw-tests-schema/types/overrides"
10+
test "github.com/coreruleset/ftw-tests-schema/types/test"
1011
)
1112

1213
func main() {
13-
data, err := types.GetFTWTestDoc().Encode()
14+
data, err := test.GetFTWTestDoc().Encode()
15+
if err != nil {
16+
panic(err)
17+
}
18+
_, err = os.Stdout.Write(data)
19+
if err != nil {
20+
panic(err)
21+
}
22+
23+
data, err = overrides.GetFTWOverridesDoc().Encode()
1424
if err != nil {
1525
panic(err)
1626
}

go.mod

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ go 1.21
44

55
require github.com/magefile/mage v1.15.0
66

7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
)
11+
712
require (
813
// Goccy verion is expected to stay at 1.9.2 (Same of go-ftw) because of https://github.com/goccy/go-yaml/issues/325
914
github.com/goccy/go-yaml v1.9.2
@@ -14,6 +19,7 @@ require (
1419
github.com/fatih/color v1.10.0 // indirect
1520
github.com/mattn/go-colorable v0.1.8 // indirect
1621
github.com/mattn/go-isatty v0.0.12 // indirect
22+
github.com/stretchr/testify v1.8.4
1723
golang.org/x/sys v0.6.0 // indirect
1824
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
1925
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ github.com/projectdiscovery/yamldoc-go v1.0.4 h1:eZoESapnMw6WAHiVgRwNqvbJEfNHEH1
2626
github.com/projectdiscovery/yamldoc-go v1.0.4/go.mod h1:8PIPRcUD55UbtQdcfFR1hpIGRWG0P7alClXNGt1TBik=
2727
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2828
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
29-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
30-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
29+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
30+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
3131
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3232
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
3333
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

mage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
1+
// Copyright 2023 CRS
22
// SPDX-License-Identifier: Apache-2.0
33

44
//go:build ignore

magefile.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Felipe Zipitria
1+
// Copyright 2023 CRS
22
// SPDX-License-Identifier: Apache-2.0
33

44
//go:build mage
@@ -16,18 +16,24 @@ import (
1616
)
1717

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

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

26-
// Format formats code in this repository.
27-
func Format() error {
26+
// Generate Go documernation files for YAML structures
27+
func Generate() error {
2828
if err := sh.RunV("go", "generate", "./..."); err != nil {
2929
return err
3030
}
31+
return nil
32+
}
33+
34+
// Format formats code in this repository.
35+
func Format() error {
36+
mg.SerialDeps(Generate)
3137

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

5359
// Lint verifies code quality.
5460
func Lint() error {
55-
if err := sh.RunV("go", "generate", "./..."); err != nil {
56-
return err
57-
}
61+
mg.SerialDeps(Generate)
5862

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

7882
// Test runs all tests.
7983
func Test() error {
84+
mg.SerialDeps(Generate)
85+
8086
if err := sh.RunV("go", "test", "./..."); err != nil {
8187
return err
8288
}
8389

8490
return nil
8591
}
8692

93+
// Generate Markdown output (printed to terminal)
8794
func Markdown() error {
95+
mg.SerialDeps(Generate)
96+
8897
if err := sh.RunV("go", "build", "./cmd/generate-doc-yaml-schema"); err != nil {
8998
return err
9099
}

0 commit comments

Comments
 (0)