@@ -76,20 +76,7 @@ public static IContainerRegistryClientFactory CreateMockRegistryClients(Immutabl
7676 clients . Add ( ( targetReference . Registry , targetReference . Repository ) ) ;
7777 }
7878
79- return CreateMockRegistryClients ( clients . Concat ( additionalClients ) . ToArray ( ) ) . factoryMock ;
80- }
81-
82- public static ( IContainerRegistryClientFactory factoryMock , ImmutableDictionary < ( Uri , string ) , MockRegistryBlobClient > blobClientMocks ) CreateMockRegistryClients ( params ( string , string ) [ ] clients )
83- {
84- var containerRegistryFactoryBuilder = new TestContainerRegistryClientFactoryBuilder ( ) ;
85-
86- foreach ( var ( registryHost , repository ) in clients )
87- {
88- containerRegistryFactoryBuilder . RegisterMockRepositoryBlobClient ( registryHost , repository ) ;
89-
90- }
91-
92- return containerRegistryFactoryBuilder . Build ( ) ;
79+ return RegistryHelper . CreateMockRegistryClients ( clients . Concat ( additionalClients ) . ToArray ( ) ) . factoryMock ;
9380 }
9481
9582 public static ITemplateSpecRepositoryFactory CreateEmptyTemplateSpecRepositoryFactory ( bool enablePublishSource = false )
@@ -139,56 +126,10 @@ public static async Task PublishModulesToRegistryAsync(ImmutableDictionary<strin
139126 {
140127 foreach ( var ( moduleName , publishInfo ) in registryModules )
141128 {
142- await PublishModuleToRegistryAsync ( clientFactory , moduleName , publishInfo . Metadata . Target , publishInfo . ModuleSource , publishSource , null ) ;
143- }
144- }
145-
146- public static async Task PublishModuleToRegistryAsync ( IContainerRegistryClientFactory clientFactory , string moduleName , string target , string moduleSource , bool publishSource , string ? documentationUri = null )
147- {
148- var featureProviderFactory = BicepTestConstants . CreateFeatureProviderFactory ( new FeatureProviderOverrides ( PublishSourceEnabled : publishSource ) ) ;
149- var dispatcher = ServiceBuilder . Create ( s => s . WithDisabledAnalyzersConfiguration ( )
150- . AddSingleton ( clientFactory )
151- . AddSingleton ( BicepTestConstants . TemplateSpecRepositoryFactory )
152- . AddSingleton ( featureProviderFactory )
153- ) . Construct < IModuleDispatcher > ( ) ;
154-
155- var targetReference = dispatcher . TryGetArtifactReference ( ArtifactType . Module , target , RandomFileUri ( ) ) . IsSuccess ( out var @ref ) ? @ref
156- : throw new InvalidOperationException ( $ "Module '{ moduleName } ' has an invalid target reference '{ target } '. Specify a reference to an OCI artifact.") ;
157-
158- var result = CompilationHelper . Compile ( moduleSource ) ;
159- if ( result . Template is null )
160- {
161- throw new InvalidOperationException ( $ "Module { moduleName } failed to produce a template.") ;
129+ await RegistryHelper . PublishModuleToRegistry ( clientFactory , moduleName , publishInfo . Metadata . Target , publishInfo . ModuleSource , publishSource , null ) ;
162130 }
163-
164- var features = featureProviderFactory . GetFeatureProvider ( result . BicepFile . FileUri ) ;
165- BinaryData ? sourcesStream = publishSource ? BinaryData . FromStream ( SourceArchive . PackSourcesIntoStream ( result . Compilation . SourceFileGrouping , features . CacheRootDirectory ) ) : null ;
166- await dispatcher . PublishModule ( targetReference , BinaryData . FromString ( result . Template . ToString ( ) ) , sourcesStream , documentationUri ) ;
167- }
168-
169- public static async Task PublishProviderToRegistryAsync ( IDependencyHelper services , string pathToIndexJson , string target )
170- {
171- var dispatcher = services . Construct < IModuleDispatcher > ( ) ;
172- var fileSystem = services . Construct < IFileSystem > ( ) ;
173-
174- var targetReference = dispatcher . TryGetArtifactReference ( ArtifactType . Provider , target , PathHelper . FilePathToFileUrl ( pathToIndexJson ) ) . IsSuccess ( out var @ref ) ? @ref
175- : throw new InvalidOperationException ( $ "Invalid target reference '{ target } '. Specify a reference to an OCI artifact.") ;
176-
177- var tgzStream = await TypesV1Archive . GenerateProviderTarStream ( fileSystem , pathToIndexJson ) ;
178-
179- await dispatcher . PublishProvider ( targetReference , tgzStream ) ;
180131 }
181132
182133 private static Uri RandomFileUri ( ) => PathHelper . FilePathToFileUrl ( Path . GetTempFileName ( ) ) ;
183-
184- public static async Task PublishAzProvider ( IDependencyHelper services , string pathToIndexJson )
185- {
186- var version = BicepTestConstants . BuiltinAzProviderVersion ;
187- var repository = "bicep/providers/az" ;
188- await PublishProviderToRegistryAsync ( services , pathToIndexJson , $ "br:{ LanguageConstants . BicepPublicMcrRegistry } /{ repository } :{ version } ") ;
189- }
190-
191- public static IContainerRegistryClientFactory CreateOciClientForAzProvider ( )
192- => CreateMockRegistryClients ( ( LanguageConstants . BicepPublicMcrRegistry , $ "bicep/providers/az") ) . factoryMock ;
193134 }
194135}
0 commit comments