-
Notifications
You must be signed in to change notification settings - Fork 19
Add file assertion #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add file assertion #147
Changes from all commits
781486a
b282aa0
fe89129
2a616dc
5b1bcbb
adeb098
571c5e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
line one | ||
line two |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
first line | ||
second line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
first line | ||
second line | ||
third line |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,16 @@ tests: | |
/books/0/author: J. R. R. Tokien | ||
/books/1/author: Joanne K. Rowling | ||
|
||
it should assert file contents on stdout: | ||
command: cat ./integration/unix/_fixtures/big_out.txt | ||
stdout: | ||
file: ./integration/unix/_fixtures/big_out.txt | ||
|
||
it should assert file contents on stderr: | ||
command: cat ./integration/unix/_fixtures/big_out.txt >&2 | ||
stderr: | ||
file: ./integration/unix/_fixtures/big_out.txt | ||
|
||
it should inherit from parent env: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind adding a failing case as well? |
||
config: | ||
inherit-env: true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,16 +48,16 @@ func TestTextMatcher_ValidateFails(t *testing.T) { | |
|
||
func TestEqualMatcher_Validate(t *testing.T) { | ||
m := EqualMatcher{} | ||
got := m.Match(1, 1) | ||
got := m.Match(2, 2) | ||
assert.True(t, got.Success) | ||
} | ||
|
||
func TestEqualMatcher_ValidateFails(t *testing.T) { | ||
m := EqualMatcher{} | ||
got := m.Match(1, 0) | ||
got := m.Match(2, 3) | ||
assert.False(t, got.Success) | ||
assert.Contains(t, got.Diff, "+0") | ||
assert.Contains(t, got.Diff, "-1") | ||
assert.Contains(t, got.Diff, "+3") | ||
assert.Contains(t, got.Diff, "-2") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that there was always a "-1" in the diff output because it tells the user how many lines changed, so this makes the test a tiny bit less brittle. |
||
} | ||
|
||
func TestContainsMatcher_Match(t *testing.T) { | ||
|
@@ -183,3 +183,24 @@ another` | |
assert.False(t, r.Success) | ||
assert.Equal(t, diff, r.Diff) | ||
} | ||
|
||
func TestFileMatcher_Match(t *testing.T) { | ||
ReadFile = func(filename string) ([]byte, error) { | ||
return []byte("line one\nline two"), nil | ||
} | ||
m := FileMatcher{} | ||
got := m.Match("line one\nline two", "fake.txt") | ||
assert.True(t, got.Success) | ||
assert.Equal(t, "", got.Diff) | ||
} | ||
|
||
func TestFileMatcher_ValidateFails(t *testing.T) { | ||
ReadFile = func(filename string) ([]byte, error) { | ||
return []byte("line one\nline two"), nil | ||
} | ||
m := FileMatcher{} | ||
got := m.Match("line one\nline three", "fake.txt") | ||
assert.False(t, got.Success) | ||
assert.Contains(t, got.Diff, "+line two") | ||
assert.Contains(t, got.Diff, "-line three") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this example still intended to work?
I am not sure the relative path to the fixtures would work
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason why this is needed is because we're not properly mocking ioutil.Readfile in the unit tests for
app.TestCommand
... 100% my fault. Here is the exact line. I opened #149 for this already and pasted the failing build that showed why this pathing was need.I can move it over to the
testdata
approach this afternoon. So the pathing can be fixed here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh okay, than it can be merged 👍