Skip to content

Commit

Permalink
Shower
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Aug 18, 2023
1 parent 339f4e5 commit 781d716
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
6 changes: 2 additions & 4 deletions pkg/modeler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"google.golang.org/protobuf/types/known/structpb"

"github.com/FuzzyMonkeyCo/monkey/pkg/internal/fm"
"github.com/FuzzyMonkeyCo/monkey/pkg/progresser"
)

var (
Expand Down Expand Up @@ -44,8 +45,5 @@ type Interface interface { // TODO models.Modeler
Validate(uint32, *structpb.Value) []string

// NewCaller is called before making each call
NewCaller(ctx context.Context, call *fm.Srv_Call, showf ShowFunc) Caller // FIXME: use Shower iface?
NewCaller(ctx context.Context, call *fm.Srv_Call, shower progresser.Shower) Caller
}

// ShowFunc can be used to display informational messages to the tester
type ShowFunc func(string, ...interface{})
11 changes: 6 additions & 5 deletions pkg/modeler/openapiv3/caller_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/FuzzyMonkeyCo/monkey/pkg/internal/fm"
"github.com/FuzzyMonkeyCo/monkey/pkg/modeler"
"github.com/FuzzyMonkeyCo/monkey/pkg/progresser"
"github.com/FuzzyMonkeyCo/monkey/pkg/runtime/ctxvalues"
)

Expand All @@ -37,7 +38,7 @@ var (
)

type tCapHTTP struct {
showf modeler.ShowFunc
shower progresser.Shower
buildHTTPRequestErr error
doErr error

Expand Down Expand Up @@ -83,9 +84,9 @@ type tCapHTTP struct {
}

// NewCaller creates a single-use modeler.Caller from a modeler.Interface instance.
func (m *oa3) NewCaller(ctx context.Context, msg *fm.Srv_Call, showf modeler.ShowFunc) modeler.Caller {
func (m *oa3) NewCaller(ctx context.Context, msg *fm.Srv_Call, shower progresser.Shower) modeler.Caller {
m.tcap = &tCapHTTP{
showf: showf,
shower: shower,
endpoint: m.vald.Spec.Endpoints[msg.GetEID()].GetJson(),
}
m.tcap.httpReq, m.tcap.buildHTTPRequestErr = m.buildHTTPRequest(ctx, msg)
Expand Down Expand Up @@ -230,7 +231,7 @@ func (c *tCapHTTP) Do(ctx context.Context) {
req = []byte(err.Error())
}
for _, line := range bytes.Split(req, br) {
c.showf("> %s", line)
c.shower.Printf("> %s\n", line)
break
}

Expand All @@ -246,7 +247,7 @@ func (c *tCapHTTP) Do(ctx context.Context) {
}
}
for _, line := range bytes.Split(rep, br) {
c.showf("< %s", line)
c.shower.Printf("< %s\n", line)
break
}
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/progresser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Shower interface {
Printf(string, ...interface{})
// Errorf formats error messages
Errorf(string, ...interface{})
} //FIXME: move ShowFunc here?
}

// Interface displays calls, resets and checks progression
type Interface interface {
Expand Down
6 changes: 1 addition & 5 deletions pkg/runtime/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ import (
)

func (rt *Runtime) call(ctx context.Context, msg *fm.Srv_Call, tagsFilter *tags.Filter, maxSteps uint64, maxDuration time.Duration) error {
showf := func(format string, s ...interface{}) {
rt.progress.Printf(format, s...)
}

log.Printf("[NFO] raw input: %.999v", msg.GetInput())
mdl := rt.models[msg.GetModelName()]
cllr := mdl.NewCaller(ctx, msg, showf)
cllr := mdl.NewCaller(ctx, msg, rt.progress)

input := cllr.RequestProto()
log.Printf("[NFO] call input: %.999v", input)
Expand Down

0 comments on commit 781d716

Please sign in to comment.