Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maeb committed Apr 27, 2021
1 parent 6dacfb4 commit 768ac65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/format/TemplateFormatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/protobuf/ptypes"
tspb "github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/nlnwa/veidemann-api/go/config/v1"
log "github.com/sirupsen/logrus"
"reflect"
"strings"
"text/template"
"time"
)

type templateFormatter struct {
Expand Down Expand Up @@ -78,7 +78,7 @@ func (tf *templateFormatter) WriteRecord(record interface{}) error {
}

func parseTemplate(templateString string) (*template.Template, error) {
ESC := string(0x1b)
ESC := fmt.Sprint(0x1b)
funcMap := template.FuncMap{
"reset": func() string { return ESC + "[0m" },
"bold": func() string { return ESC + "[1m" },
Expand All @@ -97,11 +97,11 @@ func parseTemplate(templateString string) (*template.Template, error) {
"brightcyan": func() string { return ESC + "[1;36m" },
"bgwhite": func() string { return ESC + "[47m" },
"bgbrightblack": func() string { return ESC + "[100m" },
"time": func(ts *tspb.Timestamp) string {
"time": func(ts *timestamppb.Timestamp) string {
if ts == nil {
return " "
} else {
return fmt.Sprintf("%-24.24s", ptypes.TimestampString(ts))
return fmt.Sprintf("%-24.24s", ts.AsTime().Format(time.RFC3339))
}
},
"rethinktime": func(ts map[string]interface{}) string {
Expand Down
8 changes: 5 additions & 3 deletions src/format/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package format

import (
"bytes"
"github.com/golang/protobuf/ptypes"
configV1 "github.com/nlnwa/veidemann-api/go/config/v1"
frontierV1 "github.com/nlnwa/veidemann-api/go/frontier/v1"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/types/known/timestamppb"
"testing"
"time"
)
Expand Down Expand Up @@ -50,9 +50,9 @@ func TestHasSuffix(t *testing.T) {

func TestNewFormatter(t *testing.T) {
ts, _ := time.Parse(time.RFC3339, "2019-12-24T17:00:00Z")
startTime, _ := ptypes.TimestampProto(ts)
startTime := timestamppb.New(ts)
ts, _ = time.Parse(time.RFC3339, "2019-12-31T23:59:59Z")
endTime, _ := ptypes.TimestampProto(ts)
endTime := timestamppb.New(ts)

jobExec := &frontierV1.JobExecutionStatus{Id: "id1", StartTime: startTime, EndTime: endTime}

Expand Down Expand Up @@ -80,6 +80,7 @@ func TestNewFormatter(t *testing.T) {
jobExec,
`{
"bytesCrawled": "0",
"desiredState": "UNDEFINED",
"documentsCrawled": "0",
"documentsDenied": "0",
"documentsFailed": "0",
Expand Down Expand Up @@ -110,6 +111,7 @@ id: id1
jobId: ""
startTime: "2019-12-24T17:00:00Z"
state: UNDEFINED
desiredState: UNDEFINED
urisCrawled: "0"
`},

Expand Down

0 comments on commit 768ac65

Please sign in to comment.