@@ -83,6 +83,85 @@ public async Task ContainerBuildLogsAreStreamedToAppHost()
83
83
await app . StopAsync ( ) ;
84
84
}
85
85
86
+ [ Theory ]
87
+ [ InlineData ( "testcontainer" ) ]
88
+ [ InlineData ( "TestContainer" ) ]
89
+ [ InlineData ( "test-Container" ) ]
90
+ [ InlineData ( "TEST-234-CONTAINER" ) ]
91
+ public async Task AddDockerfileUsesLowercaseResourceNameAsImageName ( string resourceName )
92
+ {
93
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
94
+ builder . Services . AddLogging ( b => b . AddXunit ( testOutputHelper ) ) ;
95
+
96
+ var ( tempContextPath , tempDockerfilePath ) = await CreateTemporaryDockerfileAsync ( ) ;
97
+
98
+ var dockerFile = builder . AddDockerfile ( resourceName , tempContextPath , tempDockerfilePath ) ;
99
+
100
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation ) ) ;
101
+ Assert . Equal ( resourceName . ToLowerInvariant ( ) , containerImageAnnotation . Image ) ;
102
+ }
103
+
104
+ [ Theory ]
105
+ [ InlineData ( "testcontainer" ) ]
106
+ [ InlineData ( "TestContainer" ) ]
107
+ [ InlineData ( "test-Container" ) ]
108
+ [ InlineData ( "TEST-234-CONTAINER" ) ]
109
+ public async Task WithDockerfileUsesLowercaseResourceNameAsImageName ( string resourceName )
110
+ {
111
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
112
+ builder . Services . AddLogging ( b => b . AddXunit ( testOutputHelper ) ) ;
113
+
114
+ var ( tempContextPath , tempDockerfilePath ) = await CreateTemporaryDockerfileAsync ( ) ;
115
+
116
+ var dockerFile = builder . AddContainer ( resourceName , "someimagename" )
117
+ . WithDockerfile ( tempContextPath , tempDockerfilePath ) ;
118
+
119
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation ) ) ;
120
+ Assert . Equal ( resourceName . ToLowerInvariant ( ) , containerImageAnnotation . Image ) ;
121
+ }
122
+
123
+ [ Fact ]
124
+ public async Task WithDockerfileUsesGeneratesDifferentHashForImageTagOnEachCall ( )
125
+ {
126
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
127
+ builder . Services . AddLogging ( b => b . AddXunit ( testOutputHelper ) ) ;
128
+
129
+ var ( tempContextPath , tempDockerfilePath ) = await CreateTemporaryDockerfileAsync ( ) ;
130
+
131
+ var dockerFile = builder . AddContainer ( "testcontainer" , "someimagename" )
132
+ . WithDockerfile ( tempContextPath , tempDockerfilePath ) ;
133
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation1 ) ) ;
134
+ var tag1 = containerImageAnnotation1 . Tag ;
135
+
136
+ dockerFile . WithDockerfile ( tempContextPath , tempDockerfilePath ) ;
137
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation2 ) ) ;
138
+ var tag2 = containerImageAnnotation2 . Tag ;
139
+
140
+ Assert . NotEqual ( tag1 , tag2 ) ;
141
+ }
142
+
143
+ [ Fact ]
144
+ public async Task WithDockerfileGeneratedImageTagCanBeOverridden ( )
145
+ {
146
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
147
+ builder . Services . AddLogging ( b => b . AddXunit ( testOutputHelper ) ) ;
148
+
149
+ var ( tempContextPath , tempDockerfilePath ) = await CreateTemporaryDockerfileAsync ( ) ;
150
+
151
+ var dockerFile = builder . AddContainer ( "testcontainer" , "someimagename" )
152
+ . WithDockerfile ( tempContextPath , tempDockerfilePath ) ;
153
+
154
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation1 ) ) ;
155
+ var generatedTag = containerImageAnnotation1 . Tag ;
156
+
157
+ dockerFile . WithImageTag ( "latest" ) ;
158
+ Assert . True ( dockerFile . Resource . TryGetLastAnnotation < ContainerImageAnnotation > ( out var containerImageAnnotation2 ) ) ;
159
+ var overriddenTag = containerImageAnnotation2 . Tag ;
160
+
161
+ Assert . NotEqual ( generatedTag , overriddenTag ) ;
162
+ Assert . Equal ( "latest" , overriddenTag ) ;
163
+ }
164
+
86
165
[ Fact ]
87
166
[ RequiresDocker ]
88
167
public async Task WithDockerfileLaunchesContainerSuccessfully ( )
@@ -110,7 +189,7 @@ public async Task WithDockerfileLaunchesContainerSuccessfully()
110
189
var kubernetes = app . Services . GetRequiredService < IKubernetesService > ( ) ;
111
190
var containers = await kubernetes . ListAsync < Container > ( ) ;
112
191
113
- var container = Assert . Single < Container > ( containers ) ;
192
+ var container = Assert . Single ( containers ) ;
114
193
Assert . Equal ( tempContextPath , container ! . Spec ! . Build ! . Context ) ;
115
194
Assert . Equal ( tempDockerfilePath , container ! . Spec ! . Build ! . Dockerfile ) ;
116
195
0 commit comments