Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: .NET

on:
push:
branches: [ "main", "ubuntu" ]
branches: [ "main" ]
pull_request:
branches: [ "main", "ubuntu" ]
branches: [ "main" ]

jobs:
build:
Expand All @@ -19,10 +19,12 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
# - name: Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of ubuntu branch trigger

# run: dotnet test --no-build --verbosity normal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump dotnet to 8.0.x

- name: Start MinIO container
run: docker run -d --name minio -p 9000:9000 -e MINIO_ROOT_USER=USERNAME -e MINIO_ROOT_PASSWORD=PASSWORD quay.io/minio/minio server /data
- name: Test
run: dotnet test --no-build --verbosity normal
114 changes: 54 additions & 60 deletions Usace.CC.Plugin.Test/BucketTesting.cs
Original file line number Diff line number Diff line change
@@ -1,82 +1,76 @@
using System;
using Amazon.S3;
using System;
using System.IO;
using System.Text;
using Xunit;

namespace Usace.CC.Plugin.Test
{
public class BucketTesting
{

private static void SetEnv(string name, string value)
public class BucketTesting
{
Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.Process);
}

[Fact]
public async void CreateBucket()
{
string profileName = "KARL";
SetEnv(profileName + "_" + EnvironmentVariables.AWS_S3_BUCKET, "test-bucket-983556");
var bucket = new AwsBucket(profileName);
using (bucket)
{
await bucket.CreateBucketIfNotExists();
}
}
private static void SetEnv(string name, string value)
{
Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.Process);
}

private static string CreateTestData()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
{
sb.Append(i.ToString() + "\n");
}
return sb.ToString();
}
[Fact]
public async void ObjectLifeCycle()
{
string profileName = "KARL";
SetEnv(profileName + "_" + EnvironmentVariables.AWS_S3_BUCKET, "thyroid");
AwsBucket bucket = new AwsBucket(profileName);
private static string CreateTestData()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
{
sb.Append(i.ToString() + "\n");
}
return sb.ToString();
}

[Fact]
public async void ObjectLifeCycle()
{
string profileName = "JACK";
SetEnv(profileName + "_" + EnvironmentVariables.AWS_S3_BUCKET, "test-bucket-1");
SetEnv(profileName + "_" + EnvironmentVariables.AWS_ACCESS_KEY_ID, "USERNAME");
SetEnv(profileName + "_" + EnvironmentVariables.AWS_SECRET_ACCESS_KEY, "PASSWORD");
SetEnv(profileName + "_" + "S3_MOCK", "true");
SetEnv(profileName + "_" + "S3_ENDPOINT", "http://127.0.0.1:9000");

await bucket.CreateBucketIfNotExists();
using (bucket)
{
var txt = CreateTestData();
string key = "test-object.txt";
var created =await bucket.CreateObject(key, txt);
Assert.True(created);
using var bucket = new AwsBucket(profileName);

var objectExists = await bucket.ObjectExists(key);
Assert.True(objectExists, "object does not exist");
await bucket.CreateBucketIfNotExists();
using (bucket)
{
var txt = CreateTestData();
string key = "test-object.txt";
var created = await bucket.CreateObject(key, txt);
Assert.True(created);

var txt2 = await bucket.ReadObjectAsText(key);
Assert.True(string.Equals(txt, txt2),"content different");
var objectExists = await bucket.ObjectExists(key);
Assert.True(objectExists, "object does not exist");

var txt2 = await bucket.ReadObjectAsText(key);
Assert.True(string.Equals(txt, txt2), "content different");

var dir = Path.Combine(Path.GetTempPath(), "karl-sub-dir-test");
var locaFileName = Path.Combine(dir, "karl.txt");
if( File.Exists(locaFileName))
File.Delete(locaFileName);
System.Console.WriteLine("saving to local file: "+locaFileName);

await bucket.SaveObjectToLocalFile(key, locaFileName);
var dir = Path.Combine(Path.GetTempPath(), "jack-sub-dir-test");
var locaFileName = Path.Combine(dir, "jack.txt");
if (File.Exists(locaFileName))
File.Delete(locaFileName);
System.Console.WriteLine("saving to local file: " + locaFileName);

Assert.True(File.Exists(locaFileName));
await bucket.SaveObjectToLocalFile(key, locaFileName);

var deleted = await bucket.DeleteObject(key);
Assert.True(deleted, "object was not deleted: " + key);
bool exists = await bucket.ObjectExists(key);
Assert.False(exists," object not deleted?");
Assert.True(File.Exists(locaFileName));

await bucket.DeleteBucket();
var deleted = await bucket.DeleteObject(key);
Assert.True(deleted, "object was not deleted: " + key);
bool exists = await bucket.ObjectExists(key);
Assert.False(exists, " object not deleted?");

exists = await bucket.BucketExists();
Assert.False(exists);
}
await bucket.DeleteBucket();

exists = await bucket.BucketExists();
Assert.False(exists);
}
}
}
}
}
24 changes: 12 additions & 12 deletions Usace.CC.Plugin.Test/PayloadJsonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Usace.CC.Plugin.Test
{
public class PayloadJsonTest
{
static string json = @"{
public class PayloadJsonTest
{
static string json = @"{
""stores"": [{
""Name"": ""FFRD"",
""ID"": ""6ba7b810-9dad-11d1-80b4-00c04fd430c8"",
Expand All @@ -37,16 +37,16 @@ public class PayloadJsonTest
}";


[Fact]
public void FromJson()
{
var p = Payload.FromJson(json);
Assert.Equal("seedgenerator", p.Inputs[0].Name);
Assert.Equal("FFRD", p.Inputs[0].StoreName);
System.Console.WriteLine(p);
}
[Fact]
public void FromJson()
{
var p = Payload.FromJson(json);
Assert.Equal("seedgenerator", p.Inputs[0].Name);
Assert.Equal("FFRD", p.Inputs[0].StoreName);
System.Console.WriteLine(p);
}



}
}
}