Skip to content

Commit

Permalink
Merge pull request #626 from k1LoW/http-openapi3
Browse files Browse the repository at this point in the history
Add `--http-openapi3` opiton to set the path to the OpenAPI v3 document for all HTTP runners
  • Loading branch information
k1LoW authored Oct 8, 2023
2 parents 53321fc + 8d6d2d6 commit 6679c73
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 45 deletions.
92 changes: 47 additions & 45 deletions book.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,52 @@ const noDesc = "[No Description]"

// book - Aggregated settings. runbook settings and run settings are aggregated.
type book struct {
desc string
runners map[string]any
vars map[string]any
rawSteps []map[string]any
debug bool
ifCond string
skipTest bool
funcs map[string]any
stepKeys []string
path string // runbook file path
httpRunners map[string]*httpRunner
dbRunners map[string]*dbRunner
grpcRunners map[string]*grpcRunner
cdpRunners map[string]*cdpRunner
sshRunners map[string]*sshRunner
profile bool
intervalStr string
interval time.Duration
loop *Loop
concurrency string
useMap bool
t *testing.T
included bool
force bool
failFast bool
skipIncluded bool
grpcNoTLS bool
grpcProtos []string
grpcImportPaths []string
runID string
runMatch *regexp.Regexp
runSample int
runShardIndex int
runShardN int
runShuffle bool
runShuffleSeed int64
runConcurrent bool
runConcurrentMax int
runRandom int
runnerErrs map[string]error
beforeFuncs []func(*RunResult) error
afterFuncs []func(*RunResult) error
capturers capturers
stdout io.Writer
stderr io.Writer
desc string
runners map[string]any
vars map[string]any
rawSteps []map[string]any
debug bool
ifCond string
skipTest bool
funcs map[string]any
stepKeys []string
path string // runbook file path
httpRunners map[string]*httpRunner
dbRunners map[string]*dbRunner
grpcRunners map[string]*grpcRunner
cdpRunners map[string]*cdpRunner
sshRunners map[string]*sshRunner
profile bool
intervalStr string
interval time.Duration
loop *Loop
concurrency string
useMap bool
t *testing.T
included bool
force bool
failFast bool
skipIncluded bool
openApi3DocLocation string
grpcNoTLS bool
grpcProtos []string
grpcImportPaths []string
runID string
runMatch *regexp.Regexp
runSample int
runShardIndex int
runShardN int
runShuffle bool
runShuffleSeed int64
runConcurrent bool
runConcurrentMax int
runRandom int
runnerErrs map[string]error
beforeFuncs []func(*RunResult) error
afterFuncs []func(*RunResult) error
capturers capturers
stdout io.Writer
stderr io.Writer
// skip some errors for `runn list`
loadOnly bool
}
Expand Down Expand Up @@ -511,6 +512,7 @@ func (bk *book) merge(loaded *book) error {
bk.force = loaded.force
}
bk.loop = loaded.loop
bk.openApi3DocLocation = loaded.openApi3DocLocation
bk.grpcNoTLS = loaded.grpcNoTLS
bk.grpcProtos = loaded.grpcProtos
bk.grpcImportPaths = loaded.grpcImportPaths
Expand Down
1 change: 1 addition & 0 deletions cmd/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func init() {
coverageCmd.Flags().StringVarP(&flgs.RunMatch, "run", "", "", flgs.Usage("RunMatch"))
coverageCmd.Flags().StringVarP(&flgs.RunID, "id", "", "", flgs.Usage("RunID"))
coverageCmd.Flags().BoolVarP(&flgs.SkipIncluded, "skip-included", "", false, flgs.Usage("SkipIncluded"))
coverageCmd.Flags().StringVarP(&flgs.HTTPOpenApi3, "http-openapi3", "", "", flgs.Usage("HTTPOpenApi3"))
coverageCmd.Flags().BoolVarP(&flgs.GRPCNoTLS, "grpc-no-tls", "", false, flgs.Usage("GRPCNoTLS"))
coverageCmd.Flags().StringSliceVarP(&flgs.GRPCProtos, "grpc-proto", "", []string{}, flgs.Usage("GRPCProtos"))
coverageCmd.Flags().StringSliceVarP(&flgs.GRPCImportPaths, "grpc-import-path", "", []string{}, flgs.Usage("GRPCImportPaths"))
Expand Down
1 change: 1 addition & 0 deletions cmd/loadt.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func init() {
loadtCmd.Flags().BoolVarP(&flgs.FailFast, "fail-fast", "", false, flgs.Usage("FailFast"))
loadtCmd.Flags().BoolVarP(&flgs.SkipTest, "skip-test", "", false, flgs.Usage("SkipTest"))
loadtCmd.Flags().BoolVarP(&flgs.SkipIncluded, "skip-included", "", false, flgs.Usage("SkipIncluded"))
loadtCmd.Flags().StringVarP(&flgs.HTTPOpenApi3, "http-openapi3", "", "", flgs.Usage("HTTPOpenApi3"))
loadtCmd.Flags().BoolVarP(&flgs.GRPCNoTLS, "grpc-no-tls", "", false, flgs.Usage("GRPCNoTLS"))
loadtCmd.Flags().StringVarP(&flgs.CaptureDir, "capture", "", "", flgs.Usage("CaptureDir"))
loadtCmd.Flags().StringSliceVarP(&flgs.Vars, "var", "", []string{}, flgs.Usage("Vars"))
Expand Down
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func init() {
runCmd.Flags().BoolVarP(&flgs.FailFast, "fail-fast", "", false, flgs.Usage("FailFast"))
runCmd.Flags().BoolVarP(&flgs.SkipTest, "skip-test", "", false, flgs.Usage("SkipTest"))
runCmd.Flags().BoolVarP(&flgs.SkipIncluded, "skip-included", "", false, flgs.Usage("SkipIncluded"))
runCmd.Flags().StringVarP(&flgs.HTTPOpenApi3, "http-openapi3", "", "", flgs.Usage("HTTPOpenApi3"))
runCmd.Flags().BoolVarP(&flgs.GRPCNoTLS, "grpc-no-tls", "", false, flgs.Usage("GRPCNoTLS"))
runCmd.Flags().StringSliceVarP(&flgs.GRPCProtos, "grpc-proto", "", []string{}, flgs.Usage("GRPCProtos"))
runCmd.Flags().StringSliceVarP(&flgs.GRPCImportPaths, "grpc-import-path", "", []string{}, flgs.Usage("GRPCImportPaths"))
Expand Down
2 changes: 2 additions & 0 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Flags struct {
SkipIncluded bool `usage:"skip running the included runbook by itself"`
RunMatch string `usage:"run all runbooks with a matching file path, treating the value passed to the option as an unanchored regular expression"`
RunID string `usage:"run the matching runbook if there is only one runbook with a forward matching ID"`
HTTPOpenApi3 string `usage:"set the path to the OpenAPI v3 document for all HTTP runners"`
GRPCNoTLS bool `usage:"disable TLS use in all gRPC runners"`
GRPCProtos []string `usage:"set the name of proto source for all gRPC runners"`
GRPCImportPaths []string `usage:"set the path to the directory where proto sources can be imported for all gRPC runners"`
Expand Down Expand Up @@ -72,6 +73,7 @@ func (f *Flags) ToOpts() ([]runn.Option, error) {
runn.Debug(f.Debug),
runn.SkipTest(f.SkipTest),
runn.SkipIncluded(f.SkipIncluded),
runn.HTTPOpenApi3(f.HTTPOpenApi3),
runn.GRPCNoTLS(f.GRPCNoTLS),
runn.GRPCProtos(f.GRPCProtos),
runn.GRPCImportPaths(f.GRPCImportPaths),
Expand Down
9 changes: 9 additions & 0 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ func New(opts ...Option) (*operator, error) {

for k, v := range bk.httpRunners {
v.operator = o
if _, ok := v.validator.(*nopValidator); ok {
val, err := newHttpValidator(&httpRunnerConfig{
OpenApi3DocLocation: bk.openApi3DocLocation,
})
if err != nil {
return nil, err
}
v.validator = val
}
o.httpRunners[k] = v
}
for k, v := range bk.dbRunners {
Expand Down
8 changes: 8 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ func Force(enable bool) Option {
}
}

// HTTPOpenApi3 - Set the path of OpenAPI Document for all HTTP runners.
func HTTPOpenApi3(l string) Option {
return func(bk *book) error {
bk.openApi3DocLocation = l
return nil
}
}

// GRPCNoTLS - Disable TLS use in all gRPC runners.
func GRPCNoTLS(noTLS bool) Option {
return func(bk *book) error {
Expand Down

0 comments on commit 6679c73

Please sign in to comment.