Skip to content

Commit

Permalink
template func: added "log"
Browse files Browse the repository at this point in the history
This new func runs logrus.Debug to output from test to stdout of the tool
  • Loading branch information
martinrode committed Mar 18, 2022
1 parent 59aac2e commit 4ec4139
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,10 @@ Example:
**semver_compare** compares to semantic version strings. This calls https://pkg.go.dev/golang.org/x/mod/semver#Compare, so check there for additional documentation. If the version is `""` the version `v0.0.0` is assumed. Before comparing, the function checks if the strings are valid. In case they are not, an error is returned.
## `log` [msg] [args...]
Write **msg** to log output. Args can be given. This uses logrus.Debugf to output.
# HTTP Server
The apitest tool includes an HTTP Server. It can be used to serve files from the local disk temporarily. The HTTP Server can run in test mode. In this mode, the apitest tool does not run any tests, but starts the HTTP Server in the foreground, until CTRL-C in pressed.
Expand Down
5 changes: 5 additions & 0 deletions pkg/lib/template/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/Masterminds/sprig/v3"
"github.com/pkg/errors"
"github.com/programmfabrik/apitest/pkg/lib/datastore"
"github.com/sirupsen/logrus"
"golang.org/x/mod/semver"

"github.com/programmfabrik/apitest/pkg/lib/util"
Expand Down Expand Up @@ -404,6 +405,10 @@ func (loader *Loader) Render(
}
return semver.Compare(v, w), nil
},
"log": func(msg string, args ...any) string {
logrus.Debugf(msg, args...)
return ""
},
}
tmpl, err := template.
New("tmpl").
Expand Down

0 comments on commit 4ec4139

Please sign in to comment.