Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Jan 9, 2025
1 parent ca71970 commit e045f3c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/Bicep.Cli.IntegrationTests/LintCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,10 @@ public async Task Lint_WithEmptyBicepConfig_ShouldProduceConfigurationError()
string testOutputPath = FileHelper.GetUniqueTestOutputPath(TestContext);
var inputFile = FileHelper.SaveResultFile(TestContext, "main.bicep", DataSets.Empty.Bicep, testOutputPath);
var configurationPath = FileHelper.SaveResultFile(TestContext, "bicepconfig.json", string.Empty, testOutputPath);
var settings = new InvocationSettings() { ModuleMetadataClient = PublicRegistryModuleIndexClientMock.CreateToThrow(new Exception("unit test failed: shouldn't call this")).Object };
var settings = new InvocationSettings() { ModuleMetadataClient = PublicRegistryModuleIndexClientMock.Create([]).Object };

var (output, error, result) = await Bicep(settings, "lint", inputFile);


result.Should().Be(1);
output.Should().BeEmpty();
error.Should().StartWith($"{inputFile}(1,1) : Error BCP271: Failed to parse the contents of the Bicep configuration file \"{configurationPath}\" as valid JSON: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ private async Task<CliResult> Test(Options options)
return await Bicep(settings, "lint", mainFile, options.NoRestore ? "--no-restore" : null);
}

[TestMethod]
[TestMethod] //asdfgasdfgasdfg2 should be failing exception is swallowed
public async Task IfLevelIsOff_ShouldNotDownloadModuleMetadata()
{
var moduleIndexClientMock = PublicRegistryModuleIndexClientMock.CreateToThrow(new Exception("shouldn't try to download metadata if rule is off"));
var result = await Test(new Options(CacheRoot)
{
Bicep = """
Expand All @@ -123,12 +124,14 @@ public async Task IfLevelIsOff_ShouldNotDownloadModuleMetadata()
""".Replace("{PREFIX}", PREFIX),
DiagnosticLevel = "off",
PublishedModules = [$"{PREFIX}/fake/avm/res/app/container-app:0.2.0"],
MetadataClient = PublicRegistryModuleIndexClientMock.CreateToThrow(new Exception("unit test failed: shouldn't try to download in this scenario")).Object,
MetadataClient = moduleIndexClientMock.Object,
});

result.Should().NotHaveStderr();
result.Should().HaveStdout("");
result.Should().Succeed();

moduleIndexClientMock.Verify(client => client.GetModuleIndexAsync(), Times.Never, "shouldn't try to download metadata if rule is off");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static IEnumerable<Failure> GetFailures(SemanticModel model, IServicePro
&& ociReference.Registry.Equals(LanguageConstants.BicepPublicMcrRegistry, StringComparison.Ordinal)
&& ociReference.Tag is string tag)
{
if (TryGetBicepModuleName(ociReference) is not string publicModulePath)
if (TryRemoveBicepModuleNamePrefix(ociReference) is not string publicModulePath)
{
continue;
}
Expand Down Expand Up @@ -144,11 +144,8 @@ private static IEnumerable<Failure> AnalyzeBicepModule(IPublicRegistryModuleMeta
}
}

private static string? TryGetBicepModuleName(IOciArtifactReference ociReference)
private static string? TryRemoveBicepModuleNamePrefix(IOciArtifactReference ociReference)
{
// asdfg IPublicRegistryModuleMetadataProvider does not return the "bicep/" that prefixes all
// public registry module paths (it's embedded in the default "bicep" alias path),
// so we need to remove it here.
var repoPath = ociReference.Repository;
if (!repoPath.StartsWith(LanguageConstants.BicepPublicMcrPathPrefix, StringComparison.Ordinal))
{
Expand Down
1 change: 1 addition & 0 deletions src/Bicep.Core/Registry/OciArtifactRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private OciManifest GetCachedManifest(OciArtifactReference ociArtifactModuleRefe
public override async Task OnRestoreArtifacts(bool forceRestore)
{
// We call this here because we don't want to run this code at all if we're running from the command line and --no-restore has been specified.
// So, if we're restoring artifacts, it's safe to also query for public module metadata
//asdfg use global options instead?
await publicRegistryModuleMetadataProvider.TryAwaitCache(forceRestore); //asdfg why are we waiting for the cache? asdfg should we be using the indexer instead?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Bicep.LangServer.UnitTests
{
// See also Bicep.LangServer.IntegrationTests/CompletionTests.cs4
// See also Bicep.LangServer.IntegrationTests/CompletionTests.cs

[TestClass]
public class BicepCompletionProviderTests
Expand Down

0 comments on commit e045f3c

Please sign in to comment.