Add Install Module Instructions to README (#17)

Closes: #16
Signed-off-by: William Lam <wlam@vmware.com>

Co-authored-by: William Lam <wlam@vmware.com>
This commit is contained in:
William Lam 2021-04-22 08:55:35 -07:00 committed by GitHub
parent 84606b0ab9
commit 3629c77dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 67 additions and 2 deletions

View File

@ -16,7 +16,29 @@ The module contains functions to
- Convert a CloudEvent object to an HTTP Message
- Convert an HTTP Message to a CloudEvent object
## Producer
## Install **CloudEvents.Sdk** Module
### Prerequisites
- [PowerShell 7.0](https://github.com/PowerShell/PowerShell/releases/tag/v7.0.4)
```powershell
Install-Module CloudEvents.Sdk
Import-Module CloudEvents.Sdk
Get-Command -Module CloudEvents.Sdk
CommandType Name Version Source ----------- ---- ------- ------
Function ConvertFrom-HttpMessage 0.2.0 CloudEvents.Sdk
Function ConvertTo-HttpMessage 0.2.0 CloudEvents.Sdk
Function New-CloudEvent 0.2.0 CloudEvents.Sdk
Function Read-CloudEventData 0.2.0 CloudEvents.Sdk
Function Read-CloudEventJsonData 0.2.0 CloudEvents.Sdk
Function Read-CloudEventXmlData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventJsonData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventXmlData 0.2.0 CloudEvents.Sdk
```
## Event Producer
### Create a CloudEvent object
```powershell
$cloudEvent = New-CloudEvent -Type 'com.example.object.deleted.v2' -Source 'mailto:cncf-wg-serverless@lists.cncf.io' -Id '6e8bc430-9c3a-11d9-9669-0800200c9a66' -Time (Get-Date)
@ -75,7 +97,7 @@ $cloudEventStructuredHttpMessage = $cloudEvent | ConvertTo-HttpMessage -ContentM
Invoke-WebRequest -Method POST -Uri 'http://my.cloudevents.server/' -Headers $cloudEventBinaryHttpMessage.Headers -Body $cloudEventBinaryHttpMessage.Body
```
## Consumer
## Event Consumer
### Convert an HTTP message to a CloudEvent object
```powershell
$cloudEvent = ConvertFrom-HttpMessage -Headers <headers> -Body <body>
@ -143,4 +165,47 @@ is converted to
### Read CloudEvent Custom Format **Data** as a **byte[]**
```powershell
$bytes = Read-CloudEventData -CloudEvent $cloudEvent
```
## Build the **CloudEvents.Sdk** Module
The `build.ps1` script
- Creates the CloudEvents PowerShell Module in a `CloudEvents` directory.
- Runs functions unit tests
- Runs local integrations tests
- Creates a catalog file for the CloudEvents Module
### Prerequisites
- [PowerShell 7.0](https://github.com/PowerShell/PowerShell/releases/tag/v7.0.4)
- [Pester 5.1.1](https://www.powershellgallery.com/packages/Pester/5.1.1)
- [dotnet SDK](https://dotnet.microsoft.com/download/dotnet/5.0)
```powershell
> ./build.ps1
[9:52:42 AM] INFO: Publish CloudEvents.Sdk Module to 'C:\git-repos\cloudevents\cloudevents-sdk-powershell\CloudEvents.Sdk'
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
CloudEventsPowerShell -> C:\git-repos\cloudevents\cloudevents-sdk-powershell\src\CloudEventsPowerShell\bin\Release\netstandard2.0\CloudEventsPowerShell.dll
CloudEventsPowerShell -> C:\git-repos\cloudevents\cloudevents-sdk-powershell\CloudEvents.Sdk\
[9:52:44 AM] INFO: Run unit tests
Starting discovery in 9 files.
Discovery finished in 294ms.
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Add-CloudEventData.Tests.ps1 1.01s (184ms|656ms)
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Add-CloudEventJsonData.Tests.ps1 329ms (39ms|279ms) [+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Add-CloudEventXmlData.Tests.ps1 336ms (58ms|267ms) [+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\ConvertFrom-HttpMessage.Tests.ps1 557ms (203ms|337ms) [+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\ConvertTo-HttpMessage.Tests.ps1 508ms (132ms|361ms) [+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\New-CloudEvent.Tests.ps1 275ms (22ms|243ms)
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Read-CloudEventData.Tests.ps1 257ms (10ms|236ms)
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Read-CloudEventJsonData.Tests.ps1 308ms (40ms|257ms)
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\unit\Read-CloudEventXmlData.Tests.ps1 310ms (53ms|246ms)
Tests completed in 3.94s
Tests Passed: 28, Failed: 0, Skipped: 0 NotRun: 0
[9:52:49 AM] INFO: Run integration tests
Starting discovery in 1 files.
Discovery finished in 176ms.
[+] C:\git-repos\cloudevents\cloudevents-sdk-powershell\test\integration\HttpIntegration.Tests.ps1 2.54s (1.77s|617ms)
Tests completed in 2.56s
Tests Passed: 5, Failed: 0, Skipped: 0 NotRun: 0
```