Skip to content

Commit

Permalink
Improve coverage of issues
Browse files Browse the repository at this point in the history
Add test cases for DumpLog, PrintLog and issue printing
  • Loading branch information
wjdp committed Nov 13, 2016
1 parent b4a29ca commit a70f02d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
48 changes: 48 additions & 0 deletions issues/issue_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package issues

import (
"github.com/daviddengcn/go-assert"
"io/ioutil"
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -41,3 +44,48 @@ func TestIssueStoreMessageMatchCount(t *testing.T) {
assert.Equals(t, "issue message match count",
iS.MessageMatchCount("notice"), 1)
}

func TestIssueStoreWriteLog(t *testing.T) {
// passes for log written using LogLevel
LOGFILE := "issue-store-test.log"
iS := NewIssueStore(ERROR)
issue1 := Issue{
Level: ERROR,
Message: "test1",
}
iS.AddIssue(issue1)
issue2 := Issue{
Level: WARNING,
Message: "test2",
}
iS.AddIssue(issue2)

iS.WriteLog(LOGFILE)
logBytes, err := ioutil.ReadFile(LOGFILE)
assert.Equals(t, "file error", err, nil)
logString := string(logBytes)

assert.IsTrue(t, "log contents", strings.Contains(
logString, "test1 --- <nil> --> <nil>"))
assert.IsFalse(t, "log contents", strings.Contains(
logString, "test2 --- <nil> --> <nil>"))

removeErr := os.Remove(LOGFILE)
assert.Equals(t, "file error", removeErr, nil)

}

func ExampleIssueStoreDumpIssues() {
// Passes for dumping all issues, ignoring LogLevel
iS := NewIssueStore(NONE)
issue := Issue{
Level: ERROR,
Message: "test1",
}
iS.AddIssue(issue)
iS.DumpIssues(true)
// Output:
// <<<<<<<<<<<<<<<<<<<<<<<<
// test1 --- <nil> --> <nil>
// >>>>>>>>>>>>>>>>>>>>>>>>
}
55 changes: 54 additions & 1 deletion issues/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestIssueSecondary(t *testing.T) {
assert.Equals(t, "issue1 secondary", issue1.secondary(), "http://example.com")
}

func ExampleIssuePrint() {
func ExampleIssuePrintLogLevel() {
doc := htmldoc.Document{
SitePath: "dir/doc.html",
}
Expand Down Expand Up @@ -82,3 +82,56 @@ func ExampleIssuePrint() {
// test2 --- dir/doc.html --> http://example.com

}

func ExampleIssuePrintLogAll() {
doc := htmldoc.Document{
SitePath: "dir/doc.html",
}
ref := htmldoc.Reference{
Document: &doc,
Path: "http://example.com",
}

issueStore := IssueStore{
LogLevel: DEBUG,
}

issue1 := Issue{
Level: ERROR,
Document: &doc,
store: &issueStore,
Message: "test1",
}
issue1.print(false)

issue2 := Issue{
Level: WARNING,
Reference: &ref,
store: &issueStore,
Message: "test2",
}
issue2.print(false)

issue3 := Issue{
Level: INFO,
Document: &doc,
store: &issueStore,
Message: "test3",
}
issue3.print(false)

issue4 := Issue{
Level: DEBUG,
Document: &doc,
store: &issueStore,
Message: "test4",
}
issue4.print(false)

// Output:
// test1 --- dir/doc.html --> <nil>
// test2 --- dir/doc.html --> http://example.com
// test3 --- dir/doc.html --> <nil>
// test4 --- dir/doc.html --> <nil>

}

0 comments on commit a70f02d

Please sign in to comment.