Skip to content

Commit

Permalink
Pipeline: cleanup 'Log' operation
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
  • Loading branch information
rkosegi committed Aug 16, 2024
1 parent 437a53a commit 9f72fdb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pipeline/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (p *exec) newCtx(a Action) *actContext {
func (p *exec) Execute(act Action) (err error) {
ctx := p.newCtx(act)
p.l.OnBefore(ctx)
defer p.l.OnAfter(ctx, err)
err = act.Do(ctx)
p.l.OnAfter(ctx, err)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pipeline/log_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (lo *LogOp) Do(ctx ActionContext) error {
}

func (lo *LogOp) String() string {
return fmt.Sprintf("Log[message=%s]", lo.Message)
return fmt.Sprintf("Log[message(%d)=%s]", len(lo.Message), strTruncIfNeeded(lo.Message, 5))
}

func (lo *LogOp) CloneWith(ctx ActionContext) Action {
Expand Down
7 changes: 7 additions & 0 deletions pipeline/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"strings"
)

func strTruncIfNeeded(in string, size int) string {
if len(in) <= size {
return in
}
return in[0:size]
}

func parseFile(path string, mode ParseFileMode) (dom.Node, error) {
data, err := os.ReadFile(path)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pipeline/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func TestSafeRenderStrPointer(t *testing.T) {
assert.Equal(t, "abc", *safeRenderStrPointer(&s, c.TemplateEngine(), c.Snapshot()))
}

func TestStrTruncIfNeeded(t *testing.T) {
assert.Equal(t, "Hello", strTruncIfNeeded("Hello world", 5))
assert.Equal(t, "Hell", strTruncIfNeeded("Hell", 5))
}

func TestSafeCopyIntSlice(t *testing.T) {
var x *[]int
assert.Nil(t, safeCopyIntSlice(nil))
Expand Down

0 comments on commit 9f72fdb

Please sign in to comment.