Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfinke/psmatcher
PSMatcher is a test utility, that lets you easily test responses and json, when some part of the response is something out of your control (autogenerated id, guid, datetime etc). (And More)
https://github.com/dfinke/psmatcher
powershell
Last synced: about 2 months ago
JSON representation
PSMatcher is a test utility, that lets you easily test responses and json, when some part of the response is something out of your control (autogenerated id, guid, datetime etc). (And More)
- Host: GitHub
- URL: https://github.com/dfinke/psmatcher
- Owner: dfinke
- License: mit
- Created: 2018-02-03T02:06:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-08T00:44:07.000Z (almost 7 years ago)
- Last Synced: 2024-10-12T13:06:40.511Z (3 months ago)
- Topics: powershell
- Language: PowerShell
- Homepage:
- Size: 1.18 MB
- Stars: 28
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PSMatcher
PSMatcher is a test utility, that lets you easier test responses and json, when some part of the response is something out of your control (autogenerated id, guid, datetime etc).It's here on the [PowerShell Gallery](https://www.powershellgallery.com/packages/PSMatcher)
* Appveyor build - [![Build status](https://ci.appveyor.com/api/projects/status/8yhhd5qu00pp04ue/branch/master?svg=true)](https://ci.appveyor.com/project/dfinke/psmatcher/branch/master)
* Travis-ci build - [![Build Status](https://travis-ci.org/dfinke/PSMatcher.svg?branch=master)](https://travis-ci.org/dfinke/PSMatcher)
# Overview
This PowerShell has been tested on Windows in both v5.1 and v6.0```powershell
Import-Module -Name "$PSScriptRoot\..\PSMatcher.psm1" -Force$actual = @"
{
"id" : "5a645a20-5225-431b-8c62-031b87f58b73",
"subnode" : {
"city" : "NY",
"zipCode" : "80-000",
"meta" : {
"name" : "foobar",
"shipping": 99.99,
"enabled" : false,
"_link" : "http://example.com?page=2",
"_something" : null,
"_arr" : [1, 2, 3],
"_date" : "2018-01-01"
}
}
}
"@$expected = @"
{
"id" : "@guid@",
"subnode" : {
"city" : "NY",
"zipCode" : "@string@",
"meta" : {
"name" : "@[email protected]('bar')",
"shipping": "@double@",
"enabled" : "@bool@",
"_link" : "@any@",
"_something" : "@null@",
"_arr" : [1, 2, 3],
"_date" : "@[email protected]()"
}
}
}
"@# True Result
Test-Json -Value $actual -Reference $expected# False Result
Test-Json -Value $actual -Reference '{}'
```
# Results
```
Successful ErrorMessage Result
---------- ------------ ------
True NMatcher.Matching.Result
False Expected value did not appear at path id. NMatcher.Matching.Result
```# In addition
The matcher also checks if elements are missing or if too many are supplied.**Stay Tuned**: Examples will be added showing how well this works with PowerShell objects and Hashtables.
# Available Expressions
* @string@
* @int@
* @double@
* @bool@
* @null@
* @any@
* @guid@# Credits
This wraps [NMatcher](https://github.com/defrag/NMatcher). Check out that readme for more detail.