Skip to content
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

Adding public API test coverage for Aspire.Hosting.Python #5110

Conversation

Zombach
Copy link
Contributor

@Zombach Zombach commented Jul 29, 2024

Initial issues #2649
Issues Check List: Validate arguments of public methods

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-codeflow for labeling automated codeflow. intentionally a different color! label Jul 29, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 29, 2024
Zombach and others added 4 commits July 30, 2024 08:38
…ting-python' of github.com:Zombach/aspire into zombach/validate-arguments-of-public-methods#aspire-hosting-python
var action = () => new PythonProjectResource(name, executablePath, projectDirectory);

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal("workingDirectory", exception.ParamName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PythonProjectResource's parameter is named projectDirectory which is then passed to the ExecutableResource..ctor to the parameter named workingDirectory.

And because the exception is being thrown from ExecutableResource we get workingDirectory instead of projectDirectory. That sounds confusing for the user. Maybe we should have the null check on the .ctor arguments for PythonProjectResource directly.

@mitchdenny @eerhardt @sebastienros Is there a pattern that we follow in such cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I would add a check, it would be more transparent.
But due to the fact that in PythonProjectResource these arguments are not used at the moment. according to CA1062, we can skip this check, since it is performed in depth.
But if someone adds interaction with arguments to PythonProjectResource, then they will have to add a check for 'null'.
That's why I'm in favor of adding it right away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types

✔️ DO set the ParamName property when throwing one of the subclasses of ArgumentException.

This property represents the name of the parameter that caused the exception to be thrown.

I read this as the ParamName should be set to the name of the parameter that was invalid. In this case projectDirectory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to do the null check in the PythonResource ctor just for clarity. I'm not a fan of the ThrowIfNull method, seems a bit odd to do it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought it probably doesn't matter to the end result.

@Zombach Zombach changed the title CA1062#Aspire.Hosting.Python Adding public API test coverage for Aspire.Hosting.Python Jul 31, 2024
@radical radical added area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication testing ☑️ and removed area-codeflow for labeling automated codeflow. intentionally a different color! labels Aug 6, 2024
@mitchdenny
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny mitchdenny enabled auto-merge (squash) August 20, 2024 23:29
@mitchdenny
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny mitchdenny merged commit e4ef146 into dotnet:main Aug 26, 2024
11 checks passed
@mitchdenny
Copy link
Member

@Zombach thanks once again for all your work on some of these PRs. Appreciate your efforts.

@Zombach Zombach deleted the zombach/validate-arguments-of-public-methods#aspire-hosting-python branch August 26, 2024 05:44
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication community-contribution Indicates that the PR has been added by a community member testing ☑️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants