Skip to content
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

Improving E2E testing #1444

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0ea5bdd
Building out files for E2E testing with example projects
WhitWaldo Jan 14, 2025
3a776c1
Building out additional integration tests action to run against all t…
WhitWaldo Jan 14, 2025
99d0df2
Merge branch 'master' into improve-e2e-testing
WhitWaldo Jan 14, 2025
cd70284
Tweak to use 'stdout' instead of 'std' leaving open the possibility t…
WhitWaldo Jan 14, 2025
072765a
Merge remote-tracking branch 'origin/improve-e2e-testing' into improv…
WhitWaldo Jan 14, 2025
5fd376d
Fixed file name
WhitWaldo Jan 14, 2025
ae1f250
Updated path to example-e2e-tests.json file relative to root working …
WhitWaldo Jan 14, 2025
fe3106d
Added some debug logic to see what's going on with reading the JSON file
WhitWaldo Jan 14, 2025
3528670
Shifting debug logic
WhitWaldo Jan 14, 2025
e7d091d
Updated tests run-on value
WhitWaldo Jan 14, 2025
724b5ac
Reordered runs-on section
WhitWaldo Jan 14, 2025
3a15780
Using strictly ubuntu-latest for now
WhitWaldo Jan 14, 2025
8241bb4
Removed windows install option
WhitWaldo Jan 14, 2025
b950d24
Fixed run script
WhitWaldo Jan 14, 2025
afa3458
Narrowing debug logic
WhitWaldo Jan 14, 2025
03af6b3
Added more debug text
WhitWaldo Jan 14, 2025
f76bd3d
Changing script style to reflect how jq is reading the arrays so they…
WhitWaldo Jan 14, 2025
6053d40
Minor tweak to find statement
WhitWaldo Jan 14, 2025
7e79668
Removed extraneous .NET install steps
WhitWaldo Jan 14, 2025
d6fed27
Updated arguments variable name
WhitWaldo Jan 14, 2025
3259f61
Added specific framework to 'dotnet run' command
WhitWaldo Jan 14, 2025
f813927
Merge branch 'master' into improve-e2e-testing
WhitWaldo Jan 14, 2025
22787c9
Removed unnecessary dotnet restore step
WhitWaldo Jan 14, 2025
14ad621
Merge remote-tracking branch 'origin/improve-e2e-testing' into improv…
WhitWaldo Jan 14, 2025
8c2316f
Removed prefix from matrix as it's not necessary, updated framework t…
WhitWaldo Jan 14, 2025
2360c44
Simplified debug output
WhitWaldo Jan 14, 2025
90193ec
Added specific .NET framework to dotnet build operation as well
WhitWaldo Jan 14, 2025
8923816
Added .NET 8 and .NET 9 as valid targets
WhitWaldo Jan 15, 2025
eae1621
Removed string test as it is known to break right now
WhitWaldo Jan 15, 2025
b6c654c
Updating crypto example to use smallfile and improve reference
WhitWaldo Jan 15, 2025
3b302b7
Updated argument name again
WhitWaldo Jan 15, 2025
6929544
Improving debug data
WhitWaldo Jan 15, 2025
1e3d8b5
Switched to double quotes
WhitWaldo Jan 15, 2025
9806df9
Removed small file from project since it couldn't be found by the E2E…
WhitWaldo Jan 15, 2025
72a3344
Merge branch 'master' into improve-e2e-testing
WhitWaldo Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/example-e2e-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"projects":[
{
"project": "Cryptography.csproj",
"tests": [
{
"name": "Encrypt & Decrypt Small File Stream",
"arguments": "1",
"expected_stdout_output": [
"== APP == Original file contents:",
"== APP == # The Road Not Taken",
"== APP == ## By Robert Lee Frost",
"== APP == ",
"== APP == Two roads diverged in a yellow wood,",
"== APP == And sorry I could not travel both",
"== APP == And be one traveler, long I stood",
"== APP == And looked down one as far as I could",
"== APP == To where it bent in the undergrowth;",
"== APP == ",
"== APP == Then took the other, as just as fair",
"== APP == And having perhaps the better claim,",
"== APP == Because it was grassy and wanted wear;",
"== APP == Though as for that, the passing there",
"== APP == Had worn them really about the same,",
"== APP == ",
"== APP == And both that morning equally lay",
"== APP == In leaves no step had trodden black",
"== APP == Oh, I kept the first for another day!",
"== APP == Yet knowing how way leads on to way,",
"== APP == I doubted if I should ever come back.",
"== APP == ",
"== APP == I shall be telling this with a sigh",
"== APP == Somewhere ages and ages hence:",
"== APP == Two roads diverged in a wood, and I,",
"== APP == I took the one less traveled by,",
"== APP == And that has made all the difference.",
"== APP == ",
"== APP == Encrypted bytes: ZGFwci5pby9lbmMvdjEKeyJrdyI6NSwid2ZrIjoiVHRRUnNneVkyMDlQZGxaZkNxcW11UC9OQlRra1plajZ2c2tGbG1nN21uSUFtZlZ3R3YxYVhVajlyMGdCb1Q4UWh3SWZJNzNUdVc0WkFjQmlhK2V1QStPelBQQkdYbWpZYmhFQlZLandTTkNRa3l1TFVWZ0d4ZUJwbm03cDA2bHFFUkV6MGpRL0NiNnFPN0ZKc1Z0ZVh6dmF4dDFBK0dtSEVEd0ZLYmtydGZOaU",
"1aeHF2bS85Y0pOTVBpNm9Zcms1eGJkK1kwcmc5bU9vZ1hmL1RidW5IUWRvc3lhSGpzc082U0l3TVUzdVdIMEdIZEFzNU95ZEhCRDdhd0kvSFFXdzEya3c4ZGNOQzd4enFPd0RGSUh1NXc3cmx1aGZmZHZCeVBoWDNwMEdBQzR6eWtvY2dUOWdBcGF0VjV4ekFjRXBGVGdycUxGdXhDSWI1dG9veUZxZ25ESnVYYktLWWxSU2hkclhBeGJnbFVBOVQxVmFMUC9hakhGaEYwTEFwajhYM2dYUXo2RDhhSUE",
"zRlM4VEJPYTUrSDR5cXkyQzk4dzhZMUFFcS9vSzI4dVB3NFROUEttUUxwb0xUeFE3VzRya3drbDRLcy9ZdExXYnRpU2pUSUN1ODNYaXB4T1JsU0w4SmQwQjU0MG14dDlqTDJOZlBJK09QV0l0VzdtWTJVcWh1bGxWWGNoODNscCs0V01OZ2tVRjJraElGRVFlSkhEakpkdTJRZGRGQXdZVDd5S3RPem5MdktYRHFQRXgwMk5mODU3NlpNS0VCb0ZXdDZuU084ZGxXSEFPMCtsbFZEbUZrRnI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4OtrVTHKNnZCoQZbBid0u0UvccFWAbkm/Tk0IVUbMcEv5pFS64h7ePkbHo5ZEaoobXwpmzXrx6a+P41OkNokIcE28A06RIqMmRUpE4uA9vje+M0xv5fpB64qoUqSW0DXFwDCVDW21O12kl1PJcU4aLdc9FOk7T5cA/PdYLJSjAo6P4J5VEIRv8xakH5X4a8hYz+BWcfH3pdcfZRLnZsU9UGMIcaiLZsB/I=",
"== APP == ",
"== APP == Decrypted value: ",
"== APP == # The Road Not Taken",
"== APP == ## By Robert Lee Frost",
"== APP == ",
"== APP == Two roads diverged in a yellow wood,",
"== APP == And sorry I could not travel both",
"== APP == And be one traveler, long I stood",
"== APP == And looked down one as far as I could",
"== APP == To where it bent in the undergrowth;",
"== APP == ",
"== APP == Then took the other, as just as fair",
"== APP == And having perhaps the better claim,",
"== APP == Because it was grassy and wanted wear;",
"== APP == Though as for that, the passing there",
"== APP == Had worn them really about the same,",
"== APP == ",
"== APP == And both that morning equally lay",
"== APP == In leaves no step had trodden black",
"== APP == Oh, I kept the first for another day!",
"== APP == Yet knowing how way leads on to way,",
"== APP == I doubted if I should ever come back.",
"== APP == ",
"== APP == I shall be telling this with a sigh",
"== APP == Somewhere ages and ages hence:",
"== APP == Two roads diverged in a wood, and I,",
"== APP == I took the one less traveled by,",
"== APP == And that has made all the difference."
],
"expectation_type": "startswith"
}
]
}
]
}
171 changes: 171 additions & 0 deletions .github/workflows/example-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: example-integration-test

on:
push:
branches:
- master
- release-*
tags:
- v*

pull_request:
branches:
- master
- release-*

jobs:
build-and-test:
name: run example-based integration tests

strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
dotnet-version: ['8.0'] #, '9.0']
include:
- dotnet-version: '8.0'
display-name: '.NET 8.0'
framework: 'net8.0'
install-version: '8.0.x'
- dotnet-version: '9.0'
display-name: '.NET 9.0'
framework: 'net9.0'
install-version: '9.0.x'

runs-on: 'ubuntu-latest'

env:
NUPKG_OUTDIR: bin/Release/nugets
GOVER: 1.20.0
GOOS: linux
GOARCH: amd64
GOPROXY: https://proxy.golang.org
DAPR_CLI_VER: 1.14.0
DAPR_RUNTIME_VER: 1.14.0
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/release-1.14/install/install.sh
DAPR_CLI_REF: ''
steps:
- name: Set up Dapr CLI
run: wget -q ${{ env.DAPR_INSTALL_URL }} -O - | /bin/bash -s ${{ env.DAPR_CLI_VER }}
- name: Checkout Dapr CLI repo to override dapr command.
uses: actions/checkout@v2
if: env.DAPR_CLI_REF != ''
with:
repository: dapr/cli
ref: ${{ env.DAPR_CLI_REF }}
path: cli
- name: Checkout Dapr repo to override daprd.
uses: actions/checkout@v2
if: env.DAPR_REF != ''
with:
repository: dapr/dapr
ref: ${{ env.DAPR_REF }}
path: dapr
- name: Set up Go from dapr/go.mod
if: env.DAPR_REF != ''
uses: actions/setup-go@v3
with:
go-version-file: "dapr/go.mod"
- name: Set up Go from cli/go.mod
if: env.DAPR_REF == '' && env.DAPR_CLI_REF != ''
uses: actions/setup-go@v3
with:
go-version-file: "cli/go.mod"
- name: Build and override dapr cli with referenced commit.
if: env.DAPR_CLI_REF != ''
run: |
cd cli
make
sudo cp dist/linux_amd64/release/dapr /usr/local/bin/dapr
cd ..
- name: Initialize Dapr runtime ${{ env.DAPR_RUNTIME_VER }}
run: |
dapr uninstall --all
dapr init --runtime-version ${{ env.DAPR_RUNTIME_VER }}
- name: Build and override daprd with referenced commit.
if: env.DAPR_REF != ''
run: |
cd dapr
make
mkdir -p $HOME/.dapr/bin/
cp dist/linux_amd64/release/daprd $HOME/.dapr/bin/daprd
cd ..
- name: Override placement service.
if: env.DAPR_REF != ''
run: |
docker stop dapr_placement
cd dapr
./dist/linux_amd64/release/placement &
- uses: actions/checkout@v1
- name: Parse release version
run: python ./.github/scripts/get_release_version.py
- name: Setup ${{ matrix.display-name }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.install-version }}
dotnet-quality: 'ga' # Prefer a GA release, but use the RC if not available
- name: Check test coverage
run: |
sudo apt-get install jq
# Find all .csproj files in the ./examples directory
all_projects=$(find ./examples -name '*.csproj' -exec basename {} \; | sed 's/.csproj//')
# Get the list of projects from example-e2e-tests.json
tested_projects=$(jq -r '.projects[].project' ./.github/workflows/example-e2e-tests.json | sed 's/.csproj//')
# Compare the lists and find projects without tests
for project in $all_projects; do
if ! echo "$tested_projects" | grep -q "$project"; then
echo "Project $project does not have any tests in example-e2e-tests.json"
fi
done

- name: Build & test projects
# disable deterministic builds, just for test run. Deterministic builds break coverage for some reason
run: |
# Parse the projects
projects=$(jq -c '.projects[]' ./.github/workflows/example-e2e-tests.json)
echo "Parsed project names:"
echo "$projects" | jq -r '.project'

# Iterate over the projects
echo "$projects" | while read project; do
project_name=$(echo $project | jq -r '.project')
echo "Project name: $project_name"

# Find the .csproj file in the ./examples directory
csproj_path=$(find ./examples/ -name $project_name)
echo "csproj path: $csproj_path"

tests=$(echo $project | jq -c '.tests[]')
echo "$tests" | while read test; do
test_name=$(echo $test | jq -r '.name')
echo "test name: $test_name"
test_arguments=$(echo $test | jq -r '.arguments')
echo "args: $test_arguments"
expectedOutputs=$(echo $test | jq -r '.expected_stdout_output[]')
expectation_type=$(echo $test | jq -r '.expectation_type')
echo "expectation_type: $expectation_type"

echo "Building and testing $project_name with .NET ${{ matrix.dotnet-version }}"
dotnet build $csproj_path --framework ${{ matrix.framework }} --configuration Release /p:GITHUB_ACTIONS=false
output=$(dotnet run --project $csproj_path --framework ${{ matrix.framework }} -- $test_arguments)

for expected in $expectedOutputs; do
if [[ "$expectation_type" == "startswith" ]]; then
if [[ "$output" != "$expected"* ]]; then
echo "Test failed for $csproj_path with .NET ${{ matrix.dotnet-version }}: Expected '$expected' not found in output"
exit 1
fi
elif [[ "$expectation_type" == "equals" ]]; then
if [[ "$output" != "$expected" ]]; then
echo "Test failed for $csproj_path with .NET ${{matrix.dotnet-version }}: Expected '$expected' not found in output"
exit 1
fi
else
if [[ "$output" != *"$expected"* ]]; then
echo "Test failed for $csproj_path with .NET ${{ matrix.dotnet-version }}: Expected '$expected' not found in output"
exit 1
fi
fi
done
done
done
8 changes: 1 addition & 7 deletions examples/Client/Cryptography/Cryptography.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand All @@ -16,10 +16,4 @@
<ProjectReference Include="..\..\..\src\Dapr.Client\Dapr.Client.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="file.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public override async Task RunAsync(CancellationToken cancellationToken)
{
using var client = new DaprClientBuilder().Build();

// The name of the file we're using as an example
const string fileName = "file.txt";
//Create the small data file
var tempSmallFile = await CreateSmallFileAsync();

Console.WriteLine("Original file contents:");
foreach (var line in await File.ReadAllLinesAsync(fileName, cancellationToken))
foreach (var line in await File.ReadAllLinesAsync(tempSmallFile, cancellationToken))
{
Console.WriteLine(line);
}

//Encrypt from a file stream and buffer the resulting bytes to an in-memory buffer
await using var encryptFs = new FileStream(fileName, FileMode.Open);
await using var encryptFs = new FileStream(tempSmallFile, FileMode.Open);

var bufferedEncryptedBytes = new ArrayBufferWriter<byte>();
await foreach (var bytes in (await client.EncryptAsync(componentName, encryptFs, keyName,
Expand Down Expand Up @@ -66,8 +66,45 @@ public override async Task RunAsync(CancellationToken cancellationToken)
Console.WriteLine("Decrypted value: ");
Console.WriteLine(decryptedValue);

//And some cleanup to delete our temp file
//And some cleanup to delete our temp files
File.Delete(tempSmallFile);
File.Delete(tempDecryptedFile);
}

private static async Task<string> CreateSmallFileAsync()
{
const string fileData = """
# The Road Not Taken
## By Robert Lee Frost

Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;

Then took the other, as just as fair
And having perhaps the better claim,
Because it was grassy and wanted wear;
Though as for that, the passing there
Had worn them really about the same,

And both that morning equally lay
In leaves no step had trodden black
Oh, I kept the first for another day!
Yet knowing how way leads on to way,
I doubted if I should ever come back.

I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference.
""";

var tempFileName = Path.GetTempFileName();
await File.WriteAllTextAsync(tempFileName, fileData);
return tempFileName;
}
}
}
2 changes: 2 additions & 0 deletions examples/Client/Cryptography/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ static async Task<int> Main(string[] args)
Console.WriteLine();
return 1;
}


}
}
26 changes: 0 additions & 26 deletions examples/Client/Cryptography/file.txt

This file was deleted.

Loading