-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into load-testStep
- Loading branch information
Showing
8 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package runner | ||
|
||
// corpusEntry is from the public go testing which references an internal structure. | ||
// corpusEntry is an alias to the same type as internal/fuzz.CorpusEntry. | ||
// We use a type alias because we don't want to export this type, and we can't | ||
// import internal/fuzz from testing. | ||
type corpusEntry = struct { | ||
Parent string | ||
Path string | ||
Data []byte | ||
Values []interface{} | ||
Generation int | ||
IsSeed bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package runner | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/kyverno/chainsaw/pkg/apis/v1alpha1" | ||
) | ||
|
||
func Run(tests ...v1alpha1.Test) (int, error) { | ||
if len(tests) == 0 { | ||
return 0, nil | ||
} | ||
flag.Parse() | ||
testing.Init() | ||
// Set the verbose test flag to true since we are not using the regular go test CLI. | ||
if err := flag.Set("test.v", "true"); err != nil { | ||
return 0, err | ||
} | ||
// TODO: flags | ||
var testDeps testDeps | ||
m := testing.MainStart( | ||
&testDeps, | ||
[]testing.InternalTest{{ | ||
Name: "chainsaw", | ||
F: func(t *testing.T) { | ||
t.Helper() | ||
run(t, tests...) | ||
}, | ||
}}, | ||
nil, | ||
nil, | ||
nil, | ||
) | ||
return m.Run(), nil | ||
} | ||
|
||
func run(t *testing.T, tests ...v1alpha1.Test) { | ||
t.Helper() | ||
for _, test := range tests { | ||
func(t *testing.T, test v1alpha1.Test) { | ||
t.Helper() | ||
t.Run(test.Name, func(t *testing.T) { | ||
t.Helper() | ||
t.Parallel() | ||
for i, step := range test.Spec.Steps { | ||
func(t *testing.T, test v1alpha1.TestStepSpec) { | ||
t.Helper() | ||
t.Run(fmt.Sprintf("step-%d", i+1), func(t *testing.T) { | ||
t.Helper() | ||
// TODO: execute step | ||
}) | ||
}(t, step) | ||
} | ||
}) | ||
}(t, test) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package runner | ||
|
||
import ( | ||
"io" | ||
"reflect" | ||
"regexp" | ||
"runtime/pprof" | ||
"time" | ||
) | ||
|
||
// testDeps implements the testDeps interface for MainStart. | ||
type testDeps struct { | ||
matchPat string | ||
matchRe *regexp.Regexp | ||
} | ||
|
||
func (d *testDeps) MatchString(pat, str string) (bool, error) { | ||
if d.matchRe == nil || d.matchPat != pat { | ||
d.matchPat = pat | ||
matchRe, err := regexp.Compile(d.matchPat) | ||
if err != nil { | ||
return false, err | ||
} | ||
d.matchRe = matchRe | ||
} | ||
return d.matchRe.MatchString(str), nil | ||
} | ||
|
||
func (*testDeps) SetPanicOnExit0(bool) {} | ||
|
||
func (*testDeps) StartCPUProfile(w io.Writer) error { | ||
return pprof.StartCPUProfile(w) | ||
} | ||
|
||
func (*testDeps) StopCPUProfile() { | ||
pprof.StopCPUProfile() | ||
} | ||
|
||
func (*testDeps) WriteProfileTo(name string, w io.Writer, debug int) error { | ||
return pprof.Lookup(name).WriteTo(w, debug) | ||
} | ||
|
||
func (*testDeps) ImportPath() string { | ||
return "" | ||
} | ||
|
||
func (*testDeps) StartTestLog(w io.Writer) {} | ||
|
||
func (*testDeps) StopTestLog() error { | ||
return nil | ||
} | ||
|
||
func (*testDeps) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error { | ||
return nil | ||
} | ||
|
||
func (*testDeps) RunFuzzWorker(func(corpusEntry) error) error { | ||
return nil | ||
} | ||
|
||
func (*testDeps) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) { | ||
return nil, nil | ||
} | ||
|
||
func (*testDeps) CheckCorpus([]interface{}, []reflect.Type) error { | ||
return nil | ||
} | ||
|
||
func (*testDeps) ResetCoverage() {} | ||
|
||
func (*testDeps) SnapshotCoverage() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Loading config (../../../testdata/commands/test/config/config_all_fields.yaml)... | ||
Running tests... | ||
Loading tests... | ||
- TODO | ||
Running tests... | ||
Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Running without configuration | ||
Running tests... | ||
Loading tests... | ||
- TODO | ||
Running tests... | ||
Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Loading config (../../../testdata/commands/test/config/empty_config.yaml)... | ||
Running tests... | ||
Loading tests... | ||
- TODO | ||
Running tests... | ||
Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Running without configuration | ||
Running tests... | ||
Loading tests... | ||
- TODO | ||
Running tests... | ||
Done. |