From aff6df2d11881bfe72847fabcd492d7dfd7d6bfc Mon Sep 17 00:00:00 2001 From: Lucas Pedroza Date: Wed, 13 Nov 2024 17:42:04 +0100 Subject: [PATCH] Fix setup --- .github/workflows/pr_test.yml | 26 ++++++++---------- DotNetSampleApp.Tests/CustomersTest.cs | 2 +- DotNetSampleApp.Tests/Setup.cs | 19 ------------- DotNetSampleApp.Tests/TestSetup.cs | 38 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 34 deletions(-) delete mode 100644 DotNetSampleApp.Tests/Setup.cs create mode 100644 DotNetSampleApp.Tests/TestSetup.cs diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index bd64bba..0df663f 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -28,24 +28,22 @@ jobs: dotnet-version: ${{ matrix.dotnet-version }} - name: Install Fauna CLI run: npm install -g fauna-shell - - name: Push schema - run: | + - name: Restore + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Push Schema and Test + run: | + fauna create-database --url=http://localhost:8443 --secret=secret ECommerceDotnet + FAUNA_SECRET=$(fauna create-key --url=http://localhost:8443 --secret=secret ECommerceDotnet | grep secret: | awk '{print $2}') cat << EOF > .fauna-project schema_directory=schema default=local [environment.local] endpoint=local - database=EcommerceDotnet + database=ECommerceDotnet EOF - cat .fauna-project - - fauna create-database --url=http://localhost:8443 --secret=secret ECommerceDotnet - fauna create-key --environment='' --url=http://localhost:8443 --secret=secret EcommerceDotnet server - fauna schema push -y --url=http://localhost:8443 --secret=secret - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + fauna schema push -y --url=http://localhost:8443 --secret=$FAUNA_SECRET + fauna schema commit -y --url=http://localhost:8443 --secret=$FAUNA_SECRET + FAUNA_SECRET=$FAUNA_SECRET dotnet test --no-build --verbosity normal diff --git a/DotNetSampleApp.Tests/CustomersTest.cs b/DotNetSampleApp.Tests/CustomersTest.cs index 018cec6..31775ba 100644 --- a/DotNetSampleApp.Tests/CustomersTest.cs +++ b/DotNetSampleApp.Tests/CustomersTest.cs @@ -21,7 +21,7 @@ public class CustomersTest [OneTimeSetUp] public void Setup() { - _fauna = new Client(new Configuration("secret") + _fauna = new Client(new Configuration(TestSetup.Secret) { Endpoint = new Uri("http://localhost:8443"), }); diff --git a/DotNetSampleApp.Tests/Setup.cs b/DotNetSampleApp.Tests/Setup.cs deleted file mode 100644 index ec3d309..0000000 --- a/DotNetSampleApp.Tests/Setup.cs +++ /dev/null @@ -1,19 +0,0 @@ -using DotNetSampleApp.Services; -using Fauna; -using NUnit.Framework; - -namespace DotNetSampleApp.Tests; - -[SetUpFixture] -public class Setup -{ - [OneTimeSetUp] - public void SetupOnce() - { - var c = new Client(new Configuration("secret") - { - Endpoint = new Uri("http://localhost:8443"), - }); - SeedService.Init(c); - } -} \ No newline at end of file diff --git a/DotNetSampleApp.Tests/TestSetup.cs b/DotNetSampleApp.Tests/TestSetup.cs new file mode 100644 index 0000000..dd7a654 --- /dev/null +++ b/DotNetSampleApp.Tests/TestSetup.cs @@ -0,0 +1,38 @@ +using DotNetSampleApp.Services; +using Fauna; +using NUnit.Framework; + +namespace DotNetSampleApp.Tests; + +[SetUpFixture] +public class TestSetup +{ + public static string Secret = ""; + + [OneTimeSetUp] + public void SetupOnce() + { + if (Environment.GetEnvironmentVariable("FAUNA_SECRET") == null) + { + var c = new Client(new Configuration("secret") + { + Endpoint = new Uri("http://localhost:8443"), + }); + Secret = c.QueryAsync(Query.FQL($$""" + let k = Key.create({role: 'admin', database: 'ECommerceDotnet'}) + k.secret + """)).Result.Data; + } + else + { + Secret = Environment.GetEnvironmentVariable("FAUNA_SECRET")!; + } + + var client = new Client(new Configuration(Secret) + { + Endpoint = new Uri("http://localhost:8443"), + }); + SeedService.Init(client); + } + +} \ No newline at end of file