-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented content type matcher
- Loading branch information
Ronald Holshausen
committed
Jun 18, 2020
1 parent
9fb20fd
commit c171797
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/ContentTypeMatcherSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package au.com.dius.pact.core.matchers | ||
|
||
import spock.lang.Specification | ||
import au.com.dius.pact.core.model.ContentType | ||
|
||
class ContentTypeMatcherSpec extends Specification { | ||
def 'matching binary data where content type matches'() { | ||
given: | ||
def path = [] | ||
def contentType = ContentType.fromString('application/pdf') | ||
def actual = ContentTypeMatcherSpec.getResourceAsStream('/sample.pdf').bytes | ||
def mismatchFactory = [create: { p1, p2, message, p3 -> | ||
new BodyMismatch(p1, p2, message, 'path') | ||
}] as MismatchFactory | ||
|
||
when: | ||
def result = MatcherExecutorKt.matchContentType(path, contentType, actual, mismatchFactory) | ||
|
||
then: | ||
result.empty | ||
} | ||
|
||
def 'matching binary data where content type does not match'() { | ||
given: | ||
def path = [] | ||
def contentType = ContentType.fromString('application/pdf') | ||
def actual = '"I\'m a PDF!"'.bytes | ||
def mismatchFactory = [create: { p1, p2, message, p3 -> | ||
new BodyMismatch(p1, p2, message, 'path') | ||
}] as MismatchFactory | ||
|
||
when: | ||
def result = MatcherExecutorKt.matchContentType(path, contentType, actual, mismatchFactory) | ||
|
||
then: | ||
!result.empty | ||
result*.mismatch == [ | ||
'Expected binary contents to have content type \'application/pdf\' but detected contents was \'text/plain\''] | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters