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: Fix CLI unit tests #1607

Merged
merged 8 commits into from
Feb 23, 2024
Merged

Conversation

michaljurecko
Copy link
Contributor

@michaljurecko michaljurecko commented Feb 22, 2024

Jira: https://keboola.atlassian.net/browse/PSGO-447

Changes:

  • Fixed bugs in CLI unit tests (from the new initiative), and other minor fixes.

@michaljurecko michaljurecko changed the title Michaljurecko psgo 447 tests: Fix TestDialogs_AskInitOptions_No_CI Feb 22, 2024
@michaljurecko michaljurecko marked this pull request as ready for review February 22, 2024 15:24
@michaljurecko michaljurecko changed the title tests: Fix TestDialogs_AskInitOptions_No_CI tests: Fix CLI unit tests Feb 22, 2024
Comment on lines +33 to +36
func NewValueWithOrigin[T any](v T, setBy SetBy) Value[T] {
return Value[T]{Value: v, SetBy: setBy}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See update tests.

@@ -20,8 +20,7 @@ import (
)

const (
SetByUnknown SetBy = iota
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed unused SetByUnknown, so uninitialized Value has set SetByDefault, and IsSet() == false, by default.

Comment on lines -25 to 27
func DefaultFlags() *Flags {
return &Flags{
func DefaultFlags() Flags {
return Flags{
CI: configmap.NewValue(true),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no reason to return pointer here.

Comment on lines -194 to 196
if v := reflect.ValueOf(target); v.Kind() != reflect.Pointer && v.Type().Elem().Kind() != reflect.Pointer {
if v := reflect.ValueOf(target); v.Kind() != reflect.Pointer || v.Type().Elem().Kind() != reflect.Struct {
return errors.Errorf(`cannot bind to type "%s": expected a pointer to a struct`, v.Type().String())
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed check.+

Comment on lines -112 to +114
f := syncInit.Flags{
Branches: configmap.NewValue("main"),
CI: configmap.NewValue(false),
}
f := syncInit.DefaultFlags()
f.Branches = configmap.NewValueWithOrigin("main", configmap.SetByFlag)
f.CI = configmap.NewValueWithOrigin(false, configmap.SetByFlag)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this test could ever work 🤔 , you have to simulate that the value has been set by the flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Yes, I found this out in several tests

Comment on lines -38 to +40
f := DefaultFlags()
// bind flags to struct
if err := configmap.Bind(utils.GetBindConfig(cmd.Flags(), args), f); err != nil {
// Bind flags to struct
f := Flags{}
if err := configmap.Bind(utils.GetBindConfig(cmd.Flags(), args), &f); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please, select f := DefaultFlags() approach or f := Flags{} approach and use it in all places.

Comment on lines -62 to 63
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0
Copy link
Contributor Author

@michaljurecko michaljurecko Feb 22, 2024

Choose a reason for hiding this comment

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

Updated lib, to fix data race, but maybe we have to wait for 0.48.1:
open-telemetry/opentelemetry-go-contrib#4895

Comment on lines 43 to 49
func (f *testFile) Close() error {
err := f.file.Close()
if f.CloseError != nil {
return f.CloseError
}
return f.file.Close()
return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix one more test on Windows, always close the underlying file.

Copy link
Contributor

@hosekpeter hosekpeter left a comment

Choose a reason for hiding this comment

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

LGTM

@michaljurecko michaljurecko merged commit 72e3731 into RFC-2023-008 Feb 23, 2024
11 checks passed
@michaljurecko michaljurecko deleted the michaljurecko-PSGO-447 branch February 23, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants