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
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ require (
go.etcd.io/etcd/tests/v3 v3.5.11
go.nhat.io/aferocopy/v2 v2.0.1
go.opencensus.io v0.24.0
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
Comment on lines -62 to 63
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

go.opentelemetry.io/contrib/propagators/b3 v1.17.0
go.opentelemetry.io/otel v1.20.0
go.opentelemetry.io/otel v1.23.0
go.opentelemetry.io/otel/bridge/opencensus v0.39.0
go.opentelemetry.io/otel/exporters/prometheus v0.39.0
go.opentelemetry.io/otel/metric v1.20.0
go.opentelemetry.io/otel/metric v1.23.0
go.opentelemetry.io/otel/sdk v1.20.0
go.opentelemetry.io/otel/sdk/metric v0.39.0
go.opentelemetry.io/otel/trace v1.20.0
go.opentelemetry.io/otel/trace v1.23.0
go.uber.org/zap v1.26.0
goa.design/goa/v3 v3.14.6
goa.design/plugins/v3 v3.14.6
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.60.1
google.golang.org/grpc v1.61.0
gopkg.in/DataDog/dd-trace-go.v1 v1.60.3
gopkg.in/Knetic/govaluate.v3 v3.0.0
v.io/x/lib v0.1.14
Expand Down Expand Up @@ -183,7 +183,7 @@ require (
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-chi/chi/v5 v5.0.11 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -240,7 +240,7 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
gocloud.dev v0.29.0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
google.golang.org/api v0.149.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 h1:7To3pQ+pZo0i3dsWEbinPNFs5gPSBOsJtx3wTT94VBY=
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
Expand Down Expand Up @@ -1047,8 +1047,8 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
Expand Down Expand Up @@ -2192,8 +2192,8 @@ go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0/go.mod h1:vEhqr0m4eTc+DWxfsXoXue2GBgV2uUwVznkGIHW/e5w=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 h1:PzIubN4/sjByhDRHLviCjJuweBXWFZWhghjg7cS28+M=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0/go.mod h1:Ct6zzQEuGK3WpJs2n4dn+wfJYzd/+hNnxMRTWjGn30M=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 h1:P+/g8GpuJGYbOp2tAdKrIPUX9JO02q8Q0YNlHolpibA=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0/go.mod h1:tIKj3DbO8N9Y2xo52og3irLsPI4GW02DSMtrVgNMgxg=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.31.0/go.mod h1:PFmBsWbldL1kiWZk9+0LBZz2brhByaGsvp6pRICMlPE=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.37.0/go.mod h1:+ARmXlUlc51J7sZeCBkBJNdHGySrdOzgzxp6VWRWM1U=
Expand All @@ -2207,8 +2207,8 @@ go.opentelemetry.io/otel v1.6.0/go.mod h1:bfJD2DZVw0LBxghOTlgnlI0CV3hLDu9XF/QKOU
go.opentelemetry.io/otel v1.6.1/go.mod h1:blzUabWHkX6LJewxvadmzafgh/wnvBSDBdOuwkAtrWQ=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI=
go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc=
go.opentelemetry.io/otel v1.20.0/go.mod h1:oUIGj3D77RwJdM6PPZImDpSZGDvkD9fhesHny69JFrs=
go.opentelemetry.io/otel v1.23.0 h1:Df0pqjqExIywbMCMTxkAwzjLZtRf+bBKLbUcpxO2C9E=
go.opentelemetry.io/otel v1.23.0/go.mod h1:YCycw9ZeKhcJFrb34iVSkyT0iczq/zYDtZYFufObyB0=
go.opentelemetry.io/otel/bridge/opencensus v0.39.0 h1:YHivttTaDhbZIHuPlg1sWsy2P5gj57vzqPfkHItgbwQ=
go.opentelemetry.io/otel/bridge/opencensus v0.39.0/go.mod h1:vZ4537pNjFDXEx//WldAR6Ro2LC8wwmFC76njAXwNPE=
go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM=
Expand All @@ -2233,8 +2233,8 @@ go.opentelemetry.io/otel/exporters/prometheus v0.39.0/go.mod h1:4jo5Q4CROlCpSPsX
go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU=
go.opentelemetry.io/otel/metric v0.28.0/go.mod h1:TrzsfQAmQaB1PDcdhBauLMk7nyyg9hm+GoQq/ekE9Iw=
go.opentelemetry.io/otel/metric v0.34.0/go.mod h1:ZFuI4yQGNCupurTXCwkeD/zHBt+C2bR7bw5JqUm/AP8=
go.opentelemetry.io/otel/metric v1.20.0 h1:ZlrO8Hu9+GAhnepmRGhSU7/VkpjrNowxRN9GyKR4wzA=
go.opentelemetry.io/otel/metric v1.20.0/go.mod h1:90DRw3nfK4D7Sm/75yQ00gTJxtkBxX+wu6YaNymbpVM=
go.opentelemetry.io/otel/metric v1.23.0 h1:pazkx7ss4LFVVYSxYew7L5I6qvLXHA0Ap2pwV+9Cnpo=
go.opentelemetry.io/otel/metric v1.23.0/go.mod h1:MqUW2X2a6Q8RN96E2/nqNoT+z9BSms20Jb7Bbp+HiTo=
go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw=
go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc=
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
Expand All @@ -2253,8 +2253,8 @@ go.opentelemetry.io/otel/trace v1.6.0/go.mod h1:qs7BrU5cZ8dXQHBGxHMOxwME/27YH2qE
go.opentelemetry.io/otel/trace v1.6.1/go.mod h1:RkFRM1m0puWIq10oxImnGEduNBzxiN7TXluRBtE+5j0=
go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA=
go.opentelemetry.io/otel/trace v1.20.0 h1:+yxVAPZPbQhbC3OfAkeIVTky6iTFpcr4SiY9om7mXSQ=
go.opentelemetry.io/otel/trace v1.20.0/go.mod h1:HJSK7F/hA5RlzpZ0zKDCHCDHm556LCDtKaAo6JmBFUU=
go.opentelemetry.io/otel/trace v1.23.0 h1:37Ik5Ib7xfYVb4V1UtnT97T1jI+AoIYkJyPkuL4iJgI=
go.opentelemetry.io/otel/trace v1.23.0/go.mod h1:GSGTbIClEsuZrGIzoEHqsVfxgn5UkggkflQwDScNUsk=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.opentelemetry.io/proto/otlp v0.11.0/go.mod h1:QpEjXPrNQzrFDZgoTo49dgHR9RYRSrg3NAKnUGl9YpQ=
go.opentelemetry.io/proto/otlp v0.12.1/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
Expand Down Expand Up @@ -2523,8 +2523,8 @@ golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri
golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I=
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -3108,8 +3108,8 @@ google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/grpc v1.52.1/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
12 changes: 6 additions & 6 deletions internal/pkg/service/cli/cmd/ci/workflow/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Flags struct {
CIPush configmap.Value[bool] `configKey:"ci-push" configUsage:"create workflow to push change in main branch to the project"`
}

func DefaultFlags() *Flags {
return &Flags{
func DefaultFlags() Flags {
return Flags{
CI: configmap.NewValue(true),
CIValidate: configmap.NewValue(true),
CIPush: configmap.NewValue(true),
Expand All @@ -35,9 +35,9 @@ func WorkflowsCommand(p dependencies.Provider) *cobra.Command {
Short: helpmsg.Read(`ci/workflows/short`),
Long: helpmsg.Read(`ci/workflows/long`),
RunE: func(cmd *cobra.Command, args []string) (err error) {
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 {
Comment on lines -38 to +40
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.

return err
}

Expand All @@ -52,7 +52,7 @@ func WorkflowsCommand(p dependencies.Provider) *cobra.Command {
}

// Ask options
options := AskWorkflowsOptions(*f, d.Dialogs())
options := AskWorkflowsOptions(f, d.Dialogs())

// Generate workflows
return workflowsGen.Run(cmd.Context(), prj.Fs(), options, d)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/service/cli/cmd/sync/init/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Flags struct {
CIMainBranch configmap.Value[string] `configKey:"ci-main-branch" configUsage:"name of the main branch for push/pull workflows"`
}

func DefaultFlags() *Flags {
return &Flags{
func DefaultFlags() Flags {
return Flags{
CI: configmap.NewValue(true),
Comment on lines -25 to 27
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.

CIValidate: configmap.NewValue(true),
CIPull: configmap.NewValue(true),
Expand Down
9 changes: 4 additions & 5 deletions internal/pkg/service/cli/dialog/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestDialogs_AskInitOptions(t *testing.T) {
}()

// Run
opts, err := syncInit.AskInitOptions(context.Background(), dialog, d, *syncInit.DefaultFlags())
opts, err := syncInit.AskInitOptions(context.Background(), dialog, d, syncInit.DefaultFlags())
assert.NoError(t, err)
assert.NoError(t, console.Tty().Close())
wg.Wait()
Expand Down Expand Up @@ -109,10 +109,9 @@ func TestDialogs_AskInitOptions_No_CI(t *testing.T) {
o.Set("ci", "false")
o.Set("branches", "main")

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)
Comment on lines -112 to +114
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


// Run
opts, err := syncInit.AskInitOptions(context.Background(), dialog, d, f)
Expand Down
13 changes: 6 additions & 7 deletions internal/pkg/service/cli/dialog/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAskWorkflowsOptionsInteractive(t *testing.T) {
}()

// Run
out := workflow.AskWorkflowsOptions(*f, dialog)
out := workflow.AskWorkflowsOptions(f, dialog)
assert.Equal(t, genWorkflows.Options{
Validate: false,
Push: true,
Expand All @@ -67,12 +67,11 @@ func TestAskWorkflowsOptionsByFlag(t *testing.T) {
o.Set(`ci-pull`, `false`)
o.Set(`ci-main-branch`, `main`)

f := workflow.Flags{
CIValidate: configmap.NewValue(false),
CIPull: configmap.NewValue(false),
CIMainBranch: configmap.NewValue("main"),
CIPush: configmap.NewValue(true),
}
f := workflow.DefaultFlags()
f.CIValidate = configmap.NewValueWithOrigin(false, configmap.SetByFlag)
f.CIPull = configmap.NewValueWithOrigin(false, configmap.SetByFlag)
f.CIMainBranch = configmap.NewValueWithOrigin("main", configmap.SetByFlag)
f.CIPush = configmap.NewValueWithOrigin(true, configmap.SetByFlag)

// Run
out := workflow.AskWorkflowsOptions(f, dialog)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/service/cli/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestValuesPriority(t *testing.T) {
err := options.Load(context.Background(), logger, env.Empty(), fs, &pflag.FlagSet{})
assert.NoError(t, err)
assert.Equal(t, "", options.GetString(key))
assert.Equal(t, configmap.SetByUnknown, options.KeySetBy(key))
assert.Equal(t, configmap.SetByDefault, options.KeySetBy(key))

// 2. Lowest priority, flag default value
flags := &pflag.FlagSet{}
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/service/common/configmap/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

SetByDefault
SetByDefault SetBy = iota
SetByConfig
SetByFlag
SetByEnv
Expand Down Expand Up @@ -192,7 +191,7 @@ func Bind(inputs BindConfig, targets ...any) error {
errs := errors.NewMultiError()
for _, target := range targets {
// Validate type
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())
}
Comment on lines -195 to 196
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.+


Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/service/common/configmap/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func NewValue[T any](v T) Value[T] {
return Value[T]{Value: v, SetBy: SetByDefault}
}

func NewValueWithOrigin[T any](v T, setBy SetBy) Value[T] {
return Value[T]{Value: v, SetBy: setBy}
}

Comment on lines +33 to +36
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.

func (v fieldValue) IsSet() bool {
return v.SetBy != SetByDefault
}
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/service/common/configmap/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ func TestNewValue(t *testing.T) {
t.Parallel()
assert.Equal(t, configmap.Value[int]{Value: 123, SetBy: configmap.SetByDefault}, configmap.NewValue(123))
}

func TestNewValueWithOrigin(t *testing.T) {
t.Parallel()
assert.Equal(t, configmap.Value[int]{Value: 123, SetBy: configmap.SetByDefault}, configmap.NewValueWithOrigin(123, configmap.SetByDefault))
assert.Equal(t, configmap.Value[int]{Value: 123, SetBy: configmap.SetByFlag}, configmap.NewValueWithOrigin(123, configmap.SetByFlag))
}
2 changes: 0 additions & 2 deletions internal/pkg/service/stream/storage/cleanup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/benbjohnson/clock"
"github.com/davecgh/go-spew/spew"
"github.com/keboola/go-client/pkg/keboola"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -95,7 +94,6 @@ func TestNode(t *testing.T) {
require.NoError(t, defRepo.Source().Create("Create source", &source).Do(ctx).Err())
sink := test.NewSink(sinkKey)
sink.Config = sink.Config.With(testconfig.LocalVolumeConfig(2, []string{"default"}))
spew.Dump(testconfig.LocalVolumeConfig(2, []string{"default"}))
require.NoError(t, defRepo.Sink().Create("Create sink", &sink).Do(ctx).Err())
require.NoError(t, tokenRepo.Put(sink.SinkKey, keboola.Token{Token: "my-token"}).Do(ctx).Err())
}
Expand Down
Loading