Skip to content

Commit 409c929

Browse files
committed
testutil: tweak naming and comments
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
1 parent af509a3 commit 409c929

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

testutil/filecontentchecker.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type fileContentChecker struct {
3535
}
3636

3737
// FileEquals verifies that the given file's content is equal to the string (or
38-
// fmt.Stringer), []byte provided, or the contents of a ReferenceFile.
38+
// fmt.Stringer), []byte provided, or the contents referred by a FileContentRef.
3939
var FileEquals check.Checker = &fileContentChecker{
4040
CheckerInfo: &check.CheckerInfo{Name: "FileEquals", Params: []string{"filename", "contents"}},
4141
exact: true,
@@ -53,8 +53,9 @@ var FileMatches check.Checker = &fileContentChecker{
5353
CheckerInfo: &check.CheckerInfo{Name: "FileMatches", Params: []string{"filename", "regex"}},
5454
}
5555

56-
// ReferenceFile wraps a file with reference contents.
57-
type ReferenceFile string
56+
// FileContentRef refers to the content of file by its name, to use in
57+
// conjunction with FileEquals.
58+
type FileContentRef string
5859

5960
func (c *fileContentChecker) Check(params []interface{}, names []string) (result bool, error string) {
6061
filename, ok := params[0].(string)
@@ -90,7 +91,7 @@ func fileContentCheck(filename string, content interface{}, exact bool) (result
9091
presentableBuf = "<binary data>"
9192
case fmt.Stringer:
9293
result = presentableBuf == content.String()
93-
case ReferenceFile:
94+
case FileContentRef:
9495
referenceFilename := string(content)
9596
reference, err := ioutil.ReadFile(referenceFilename)
9697
if err != nil {
@@ -115,7 +116,7 @@ func fileContentCheck(filename string, content interface{}, exact bool) (result
115116
result = content.Match(buf)
116117
case fmt.Stringer:
117118
result = strings.Contains(presentableBuf, content.String())
118-
case ReferenceFile:
119+
case FileContentRef:
119120
error = "Non-exact match with reference file is not supported"
120121
default:
121122
error = fmt.Sprintf("Cannot compare file contents with something of type %T", content)

testutil/filecontentchecker_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func (s *fileContentCheckerSuite) TestFileEquals(c *check.C) {
5252
testCheck(c, FileEquals, true, "", filename, content)
5353
testCheck(c, FileEquals, true, "", filename, []byte(content))
5454
testCheck(c, FileEquals, true, "", filename, myStringer{content})
55-
testCheck(c, FileEquals, true, "", filename, ReferenceFile(filename))
56-
testCheck(c, FileEquals, true, "", filename, ReferenceFile(equalRefereceFilename))
55+
testCheck(c, FileEquals, true, "", filename, FileContentRef(filename))
56+
testCheck(c, FileEquals, true, "", filename, FileContentRef(equalRefereceFilename))
5757

5858
twofer := content + content
5959
testCheck(c, FileEquals, false, "Failed to match with file contents:\nnot-so-random-string", filename, twofer)
@@ -65,7 +65,7 @@ func (s *fileContentCheckerSuite) TestFileEquals(c *check.C) {
6565
testCheck(c, FileEquals, false, "Cannot compare file contents with something of type int", filename, 1)
6666
testCheck(c, FileEquals, false,
6767
fmt.Sprintf("Failed to match contents with reference file \"%s\":\nnot-so-random-string", notEqualRefereceFilename),
68-
filename, ReferenceFile(notEqualRefereceFilename))
68+
filename, FileContentRef(notEqualRefereceFilename))
6969
}
7070

7171
func (s *fileContentCheckerSuite) TestFileContains(c *check.C) {
@@ -92,7 +92,7 @@ func (s *fileContentCheckerSuite) TestFileContains(c *check.C) {
9292
testCheck(c, FileContains, false, "Filename must be a string", 42, "")
9393
testCheck(c, FileContains, false, "Cannot compare file contents with something of type int", filename, 1)
9494
testCheck(c, FileContains, false, `Non-exact match with reference file is not supported`,
95-
filename, ReferenceFile(filename))
95+
filename, FileContentRef(filename))
9696
}
9797

9898
func (s *fileContentCheckerSuite) TestFileMatches(c *check.C) {
@@ -112,5 +112,5 @@ func (s *fileContentCheckerSuite) TestFileMatches(c *check.C) {
112112
testCheck(c, FileMatches, false, "Filename must be a string", 42, ".*")
113113
testCheck(c, FileMatches, false, "Regex must be a string", filename, 1)
114114
testCheck(c, FileContains, false, `Non-exact match with reference file is not supported`,
115-
filename, ReferenceFile(filename))
115+
filename, FileContentRef(filename))
116116
}

0 commit comments

Comments
 (0)