-
Notifications
You must be signed in to change notification settings - Fork 458
Log warning message for unsupported action with Java #4582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
satvu
wants to merge
4
commits into
main
Choose a base branch
from
satvu/java-error-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,13 @@ public async Task UpdateLanguageAndRuntime() | |
throw new CliException("Selected language doesn't match worker set in local.settings.json." + | ||
$"Selected worker is: {_workerRuntime} and selected language is: {workerRuntimeSelected}"); | ||
} | ||
|
||
if (workerRuntimeSelected == WorkerRuntime.Java) | ||
{ | ||
ColoredConsole | ||
.WriteLine($"This action is not supported when using the core tools directly. Please use one of the supported environments to test {workerRuntimeSelected} apps locally as specified by" + | ||
$"https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local?pivots=programming-language-java"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. placeholder - will prob add a fw link that points to https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local?pivots=programming-language-java#local-development-environments |
||
} | ||
} | ||
else if (string.IsNullOrWhiteSpace(Language)) | ||
{ | ||
|
62 changes: 62 additions & 0 deletions
62
test/Cli/Func.UnitTests/ActionsTests/CreateFunctionActionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Azure.Functions.Cli.Actions.LocalActions; | ||
using Azure.Functions.Cli.Helpers; | ||
using Azure.Functions.Cli.Interfaces; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Azure.Functions.Cli.UnitTests.ActionsTests | ||
{ | ||
public class CreateFunctionActionTests | ||
{ | ||
[Fact] | ||
public async Task UpdateLanguageAndRuntime_ThrowsCliException_ForJavaWorkerRuntime() | ||
{ | ||
// Arrange | ||
var templatesManager = new Mock<ITemplatesManager>(); | ||
var secretsManager = new Mock<ISecretsManager>(); | ||
var contextHelpManager = new Mock<IContextHelpManager>(); | ||
var action = new CreateFunctionAction(templatesManager.Object, secretsManager.Object, contextHelpManager.Object) | ||
{ | ||
Language = "java" | ||
}; | ||
|
||
// Set the current worker runtime to Java, mocking the behavior where func init has already been run | ||
GlobalCoreToolsSettings.CurrentWorkerRuntime = WorkerRuntime.Java; | ||
|
||
// Ensure local.settings.json exists in the current directory | ||
var localSettingsPath = Path.Combine(Environment.CurrentDirectory, "local.settings.json"); | ||
File.WriteAllText(localSettingsPath, "{}"); // Write a minimal valid JSON | ||
|
||
// Simulate worker runtime is Java | ||
typeof(CreateFunctionAction) | ||
.GetField("_workerRuntime", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) | ||
.SetValue(action, WorkerRuntime.Java); | ||
|
||
var stringWriter = new StringWriter(); | ||
var originalOut = Console.Out; | ||
Console.SetOut(stringWriter); | ||
|
||
try | ||
{ | ||
// make sure no error is thrown | ||
await action.UpdateLanguageAndRuntime(); | ||
|
||
// Assert | ||
var output = stringWriter.ToString(); | ||
Assert.Contains("This action is not supported", output); | ||
Assert.Contains("Java", output); | ||
} | ||
finally | ||
{ | ||
Console.SetOut(originalOut); | ||
if (File.Exists(localSettingsPath)) | ||
{ | ||
File.Delete(localSettingsPath); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should happen much sooner and for all init and new. (Maybe in the GlobalSettings init method).
Scenarios to validate: