Skip to content

Commit

Permalink
Make test in scipipe cmd timezone independent
Browse files Browse the repository at this point in the history
Make test in scipipe cmd timezone independent
  • Loading branch information
samuell committed Jun 13, 2019
1 parent 9b3dd76 commit 15ba30a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/scipipe/audit_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func formatTaskHTML(fileName string, auditInfo *scipipe.AuditInfo) (outHTML stri
}
outHTML += fmt.Sprintf(" <tr><th>Tags:</th><td><pre>%v</pre></td></tr>\n", strings.Join(tags, ", "))

outHTML += fmt.Sprintf(" <tr><th>Start time:</th><td>%s</td></tr>\n", auditInfo.StartTime.Format(`2006-01-02 15:04:05<span class="greyout">.000 -0700 MST</span>`))
outHTML += fmt.Sprintf(" <tr><th>Finish time:</th><td>%s</td></tr>\n", auditInfo.FinishTime.Format(`2006-01-02 15:04:05<span class="greyout">.000 -0700 MST</span>`))
outHTML += fmt.Sprintf(" <tr><th>Start time:</th><td>%s<span class=\"greyout\">%s</span></td></tr>\n", auditInfo.StartTime.Format(`2006-01-02 15:04:05`), auditInfo.StartTime.Format(`.000 -0700 MST`))
outHTML += fmt.Sprintf(" <tr><th>Finish time:</th><td>%s<span class=\"greyout\">%s</span></td></tr>\n", auditInfo.FinishTime.Format(`2006-01-02 15:04:05`), auditInfo.FinishTime.Format(`.000 -0700 MST`))
et := auditInfo.ExecTimeNS
outHTML += fmt.Sprintf(" <tr><th>Execution time:</th><td>%s</td></tr>\n", et.Truncate(time.Millisecond).String())
//upStreamHTML := ""
Expand Down
15 changes: 13 additions & 2 deletions cmd/scipipe/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/scipipe/scipipe"
"regexp"
)

func TestNewCmd(t *testing.T) {
Expand Down Expand Up @@ -52,8 +53,18 @@ func TestAudit2HTMLCmd(t *testing.T) {
if err != nil {
t.Error(errWrap(err, "Could not read HTML file:"+htmlFile).Error())
}
if string(htmlBytes) != expectedContent {
t.Errorf("Converted HTML content of %s was not as expected.\nEXPECTED:\n%s\nACTUAL:\n%s\n", htmlFile, expectedContent, string(htmlBytes))

actualContent := string(htmlBytes)

// Remove timezone dependent part of the date/time strings in both the
// expected and actual content, as they will otherwise fail the test in
// some timezones
re, err := regexp.Compile(`\.\d\d\d[^<]*`)
actualContent = re.ReplaceAllString(actualContent, "")
expectedContent = re.ReplaceAllString(expectedContent, "")

if actualContent != expectedContent {
t.Errorf("Converted HTML content of %s was not as expected.\nEXPECTED:\n%s\nACTUAL:\n%s\n", htmlFile, expectedContent, actualContent)
}
cleanFiles(t, htmlFile)
}
Expand Down

0 comments on commit 15ba30a

Please sign in to comment.