-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocalStackProjectExtensionsTests.cs
More file actions
159 lines (127 loc) · 6.82 KB
/
LocalStackProjectExtensionsTests.cs
File metadata and controls
159 lines (127 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
namespace Aspire.Hosting.LocalStack.Unit.Tests.Extensions;
public class LocalStackProjectExtensionsTests
{
[Test]
public async Task WithReference_Should_Add_LocalStack_Reference_To_Project()
{
const string testProjectResourceName = "test-project";
var (app, projectResource) = TestApplicationBuilder.CreateWithResource<ProjectResource>(testProjectResourceName, builder =>
{
var (options, _, _) = TestDataBuilders.CreateMockLocalStackOptions();
var localStack = builder.AddLocalStack(localStackOptions: options);
builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath())
.WithReference(localStack);
});
var localStackResource = app.GetResource<ILocalStackResource>("localstack");
await projectResource.ShouldHaveLocalStackEnabledAnnotation(localStackResource);
}
[Test]
public async Task WithReference_Should_Return_Builder_When_LocalStack_Is_Null()
{
const string testProjectResourceName = "test-project";
IResourceBuilder<ProjectResource>? capturedResult = null;
IResourceBuilder<ProjectResource>? capturedBuilder = null;
var (app, projectResource) = TestApplicationBuilder.CreateWithResource<ProjectResource>(testProjectResourceName, builder =>
{
var projectBuilder = builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath());
var result = projectBuilder.WithReference(localStackBuilder: null);
capturedBuilder = projectBuilder;
capturedResult = result;
});
// Should return the same builder
await Assert.That(capturedResult).IsSameReferenceAs(capturedBuilder);
await Assert.That(app.HasResource<ILocalStackResource>("localstack")).IsFalse();
await projectResource.ShouldNotHaveLocalStackEnabledAnnotation();
}
[Test]
public async Task WithReference_Should_Return_Builder_When_LocalStack_Is_Disabled()
{
const string testProjectResourceName = "test-project";
var (app, cfResource) = TestApplicationBuilder.CreateWithResource<ProjectResource>(testProjectResourceName, builder =>
{
var projectBuilder = builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath());
var (disabledOptions, _, _) = TestDataBuilders.CreateMockLocalStackOptions(useLocalStack: false);
var localStack = builder.AddLocalStack(localStackOptions: disabledOptions);
projectBuilder.WithReference(localStackBuilder: localStack);
});
await Assert.That(app.HasResource<ILocalStackResource>("localstack")).IsFalse();
await cfResource.ShouldNotHaveLocalStackEnabledAnnotation();
}
[Test]
public async Task WithReference_Should_Throw_ArgumentNullException_When_Builder_Is_Null()
{
IResourceBuilder<ProjectResource> builder = null!;
var localStack = Substitute.For<IResourceBuilder<ILocalStackResource>>();
await Assert.That(() => builder.WithReference(localStack)).ThrowsExactly<ArgumentNullException>();
}
[Test]
public async Task WithReference_Should_Establish_Bidirectional_Reference()
{
const string testProjectResourceName = "test-project";
using var app = TestApplicationBuilder.Create(builder =>
{
var (options, _, _) = TestDataBuilders.CreateMockLocalStackOptions();
var localStack = builder.AddLocalStack(localStackOptions: options);
builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath())
.WithReference(localStack);
});
var localStackResource = app.GetResource<ILocalStackResource>("localstack");
var projectResource = app.GetResource<ProjectResource>(testProjectResourceName);
await projectResource.ShouldHaveLocalStackEnabledAnnotation(localStackResource);
await localStackResource.ShouldHaveReferenceToResource(projectResource);
}
[Test]
public async Task WithReference_Should_Add_Wait_Dependency_On_LocalStack()
{
const string testProjectResourceName = "test-project";
using var app = TestApplicationBuilder.Create(builder =>
{
var (options, _, _) = TestDataBuilders.CreateMockLocalStackOptions();
var localStack = builder.AddLocalStack(localStackOptions: options);
builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath())
.WithReference(localStack);
});
var localStackResource = app.GetResource<ILocalStackResource>("localstack");
var projectResource = app.GetResource<ProjectResource>(testProjectResourceName);
await projectResource.ShouldWaitFor(localStackResource);
}
[Test]
public async Task WithReference_Should_Configure_LocalStack_Environment_Variables()
{
const string testProjectResourceName = "test-project";
using var app = TestApplicationBuilder.Create(builder =>
{
var (options, _, _) = TestDataBuilders.CreateMockLocalStackOptions(
useLocalStack: true,
regionName: "us-west-1",
edgePort: 4567);
var localStack = builder.AddLocalStack(localStackOptions: options);
builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath())
.WithReference(localStack);
});
var projectResource = app.GetResource<ProjectResource>(testProjectResourceName);
var localStackResource = app.GetResource<ILocalStackResource>("localstack");
await projectResource.ShouldHaveLocalStackEnvironmentConfiguration(localStackResource);
}
[Test]
public async Task WithReference_Should_Not_Duplicate_References_When_Called_Multiple_Times()
{
const string testProjectResourceName = "test-project";
using var app = TestApplicationBuilder.Create(builder =>
{
var (options, _, _) = TestDataBuilders.CreateMockLocalStackOptions();
var localStack = builder.AddLocalStack(localStackOptions: options);
var projectBuilder = builder.AddProject(testProjectResourceName, TestDataBuilders.GetTestProjectPath());
// Call WithReference multiple times
projectBuilder.WithReference(localStack);
projectBuilder.WithReference(localStack);
projectBuilder.WithReference(localStack);
});
var localStackResource = app.GetResource<ILocalStackResource>("localstack");
var referenceAnnotations = localStackResource.Annotations
.OfType<LocalStackReferenceAnnotation>()
.Where(a => string.Equals(a.Resource.Name, testProjectResourceName, StringComparison.Ordinal))
.ToList();
await Assert.That(referenceAnnotations).HasSingleItem();
}
}