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

tests: update unit tests #68

Merged
merged 8 commits into from
Mar 1, 2024
Merged

Conversation

ainghazal
Copy link
Collaborator

Additionally, I'm instrumenting the integration test, and merging the coverage profile so that we have a combined measure of the code exercised by coverage and unit tests.

Checklist

  • I have read the contribution guidelines
  • Iff you changed code related to services, or inter-service communication, make sure you update the diagrams in ARCHITECTURE.md.
  • Reference issue for this pull request: NA

Additionally, I'm instrumenting the integration test, and merging the
coverage profile so that we have a combined measure of the code
exercised by coverage and unit tests.
Copy link
Contributor

@bassosimone bassosimone left a comment

Choose a reason for hiding this comment

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

🎻

Great work! I only have requests for minor changes here!

// WithConfigFile configures OpenVPNOptions parsed from the given file.
func WithConfigFile(configPath string) Option {
return func(config *Config) {
openvpnOpts, err := ReadConfigFile(configPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not super convinced by panicking here. Ideally, given that this is a library function, I suppose it would instead be better to return an error to the caller. A strategy to do this could be the following:

  1. you redefine Option as func(*Config) error

  2. when you are invoking the sequence of functions you in NewConfig, you also check for errors

Copy link
Collaborator Author

@ainghazal ainghazal Feb 21, 2024

Choose a reason for hiding this comment

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

true, I agree that panic is not a good thing to do here. I got too used to add a few asserts for incorrect values, but this is public-facing API.

I think I would prefer to move this to a new issue to work after merging #70 , since I've split and moved the code dealing with config (created #69 to track this).

}

func parseProto(p []string, o *OpenVPNOptions) error {
func parseProto(p []string, o *OpenVPNOptions) (*OpenVPNOptions, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm missing some information to fully understand this change in pattern. AFAICT, it should not be necessary to return the o pointer, given that you're mutating it and it's available to the caller--can you elaborate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suspect my reasoning here was to move to return a copy in the future and not modify the passed struct, but you're right that this might be unnecessary, especially since there's no other modification that uses this value.

do you think it's better to revert to the previous state and just return err?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fwiw, I think mutating makes for confusing tests

617                         name:    "default",
618                         args:    args{o: &OpenVPNOptions{}},
619                         wantErr: nil,

and then instead of got := foo(tt.args.o} I need to check for mutation of the argument. I think it makes a cleaner API, but this needs more work than done here.

if err != nil {
return nil, err
}
defer mustClose(f)
Copy link
Contributor

Choose a reason for hiding this comment

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

yay!

internal/model/vpnoptions_test.go Outdated Show resolved Hide resolved
internal/model/vpnoptions_test.go Outdated Show resolved Hide resolved
internal/model/vpnoptions_test.go Outdated Show resolved Hide resolved
// Package optional implements optional values.
// Package optional contains safer code to handle optional values.
// This package is taken from probe-cli/internal/optional.
// Copyright 2024, Simone Basso
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2024, Simone Basso

I think there's no need, but thank you 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's a good practice when copying code verbatim. software archaeologists from the future will be grateful.

Comment on lines +2 to +3

// Copyright 2024, Simone Basso
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2024, Simone Basso

aaaw, there's no need! 😊

internal/session/datachannelkey.go Outdated Show resolved Hide resolved
@ainghazal ainghazal self-assigned this Mar 1, 2024
@ainghazal ainghazal merged commit 9de7227 into ooni:main Mar 1, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants