Skip to content

Commit

Permalink
update latest ecdysis and root test
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Dec 18, 2024
1 parent 03fbbbf commit 370a638
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 58 deletions.
21 changes: 10 additions & 11 deletions cmd/conduit/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
)

var (
_ ecdysis.CommandWithFlags = (*RootCommand)(nil)
_ ecdysis.CommandWithExecute = (*RootCommand)(nil)
_ ecdysis.CommandWithDocs = (*RootCommand)(nil)
_ ecdysis.CommandWithSubCommands = (*RootCommand)(nil)
_ ecdysis.CommandWithConfiguration = (*RootCommand)(nil)
_ ecdysis.CommandWithFlags = (*RootCommand)(nil)
_ ecdysis.CommandWithExecute = (*RootCommand)(nil)
_ ecdysis.CommandWithDocs = (*RootCommand)(nil)
_ ecdysis.CommandWithSubCommands = (*RootCommand)(nil)
_ ecdysis.CommandWithConfig = (*RootCommand)(nil)
)

type RootFlags struct {
Expand All @@ -55,15 +55,14 @@ func (c *RootCommand) Execute(_ context.Context) error {
return nil
}

func (c *RootCommand) ParseConfig() ecdysis.Config {
func (c *RootCommand) Config() ecdysis.Config {
path := filepath.Dir(c.flags.ConduitCfgPath)
c.cfg = conduit.DefaultConfigWithBasePath(path)

return ecdysis.Config{
EnvPrefix: "CONDUIT",
ParsedCfg: &c.cfg,
ConfigPath: c.flags.ConduitCfgPath,
DefaultCfg: c.cfg,
EnvPrefix: "CONDUIT",
Parsed: &c.cfg,
Path: c.flags.ConduitCfgPath,
DefaultValues: conduit.DefaultConfigWithBasePath(path),
}
}

Expand Down
91 changes: 48 additions & 43 deletions cmd/conduit/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,66 @@ import (
"testing"

"github.com/conduitio/ecdysis"
isT "github.com/matryer/is"
"github.com/matryer/is"
"github.com/spf13/pflag"
)

func TestRootCommandFlags(t *testing.T) {
is := isT.New(t)
is := is.New(t)

expectedFlags := []struct {
longName string
shortName string
required bool
usage string
persistent bool
hidden bool
}{
{longName: "config.path", persistent: true},
{longName: "version", shortName: "v", persistent: true},
{longName: "db.type"},
{longName: "db.badger.path"},
{longName: "db.postgres.connection-string"},
{longName: "db.postgres.table"},
{longName: "db.sqlite.path"},
{longName: "db.sqlite.table"},
{longName: "api.enabled"},
{longName: "http.address"},
{longName: "grpc.address"},
{longName: "log.level"},
{longName: "log.format"},
{longName: "connectors.path"},
{longName: "processors.path"},
{longName: "pipelines.path"},
{longName: "pipelines.exit-on-degraded"},
{longName: "pipelines.error-recovery.min-delay"},
{longName: "pipelines.error-recovery.max-delay"},
{longName: "pipelines.error-recovery.backoff-factor"},
{longName: "pipelines.error-recovery.max-retries"},
{longName: "pipelines.error-recovery.max-retries-window"},
{longName: "schema-registry.type"},
{longName: "schema-registry.confluent.connection-string"},
{longName: "preview.pipeline-arch-v2"},
{longName: "dev.cpuprofile"},
{longName: "dev.memprofile"},
{longName: "dev.blockprofile"},
{longName: "config.path", usage: "global conduit configuration file"},
{longName: "version", shortName: "v", usage: "show current Conduit version", persistent: true},
{longName: "db.type", usage: "database type; accepts badger,postgres,inmemory,sqlite"},
{longName: "db.badger.path", usage: "path to badger DB"},
{longName: "db.postgres.connection-string", usage: "postgres connection string, may be a database URL or in PostgreSQL keyword/value format"},
{longName: "db.postgres.table", usage: "postgres table in which to store data (will be created if it does not exist)"},
{longName: "db.sqlite.path", usage: "path to sqlite3 DB"},
{longName: "db.sqlite.table", usage: "sqlite3 table in which to store data (will be created if it does not exist)"},
{longName: "api.enabled", usage: "enable HTTP and gRPC API"},
{longName: "http.address", usage: "address for serving the HTTP API"},
{longName: "grpc.address", usage: "address for serving the gRPC API"},
{longName: "log.level", usage: "sets logging level; accepts debug, info, warn, error, trace"},
{longName: "log.format", usage: "sets the format of the logging; accepts json, cli"},
{longName: "connectors.path", usage: "path to standalone connectors' directory"},
{longName: "processors.path", usage: "path to standalone processors' directory"},
{longName: "pipelines.path", usage: "path to pipelines' directory"},
{longName: "pipelines.exit-on-degraded", usage: "exit Conduit if a pipeline is degraded"},
{longName: "pipelines.error-recovery.min-delay", usage: "minimum delay before restart"},
{longName: "pipelines.error-recovery.max-delay", usage: "maximum delay before restart"},
{longName: "pipelines.error-recovery.backoff-factor", usage: "backoff factor applied to the last delay"},
{longName: "pipelines.error-recovery.max-retries", usage: "maximum number of retries"},
{longName: "pipelines.error-recovery.max-retries-window", usage: "amount of time running without any errors after which a pipeline is considered healthy"},
{longName: "schema-registry.type", usage: "schema registry type; accepts builtin,confluent"},
{longName: "schema-registry.confluent.connection-string", usage: "confluent schema registry connection string"},
{longName: "preview.pipeline-arch-v2", usage: "enables experimental pipeline architecture v2 (note that the new architecture currently supports only 1 source and 1 destination per pipeline)"},
{longName: "dev.cpuprofile", usage: "write CPU profile to file"},
{longName: "dev.memprofile", usage: "write memory profile to file"},
{longName: "dev.blockprofile", usage: "write block profile to file"},
}

c := &RootCommand{}
flags := c.Flags()
e := ecdysis.New()
c := e.MustBuildCobraCommand(&RootCommand{})

for _, ef := range expectedFlags {
var foundFlag *ecdysis.Flag
for _, f := range flags {
if f.Long == ef.longName {
foundFlag = &f
break
}
}
persistentFlags := c.PersistentFlags()
cmdFlags := c.Flags()

for _, f := range expectedFlags {
var cf *pflag.Flag

is.True(foundFlag != nil)
if f.persistent {
cf = persistentFlags.Lookup(f.longName)
} else {
cf = cmdFlags.Lookup(f.longName)
}
is.True(cf != nil)
is.Equal(f.longName, cf.Name)
is.Equal(f.shortName, cf.Shorthand)
is.Equal(cf.Usage, f.usage)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/conduitio/conduit-connector-sdk v0.12.0
github.com/conduitio/conduit-processor-sdk v0.4.0
github.com/conduitio/conduit-schema-registry v0.2.2
github.com/conduitio/ecdysis v0.0.0-20241217205706-d372dbe18745
github.com/conduitio/ecdysis v0.0.0-20241218142415-9853ff79b597
github.com/conduitio/yaml/v3 v3.3.0
github.com/dop251/goja v0.0.0-20240806095544-3491d4a58fbe
github.com/dop251/goja_nodejs v0.0.0-20231122114759-e84d9a924c5c
Expand All @@ -41,6 +41,7 @@ require (
github.com/prometheus/common v0.61.0
github.com/rs/zerolog v1.33.0
github.com/sourcegraph/conc v0.3.0
github.com/spf13/pflag v1.0.5
github.com/stealthrocket/wazergo v0.19.1
github.com/tetratelabs/wazero v1.8.2
github.com/twmb/franz-go/pkg/sr v1.2.0
Expand Down Expand Up @@ -319,7 +320,6 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ github.com/conduitio/conduit-processor-sdk v0.4.0 h1:wF1Fj31aneNixNbW5rJ0/5Q3vwW
github.com/conduitio/conduit-processor-sdk v0.4.0/go.mod h1:Jj9ZBTee7nO0XeociDxe9gSvLFN1GbPWP1Aj04DPeZQ=
github.com/conduitio/conduit-schema-registry v0.2.2 h1:Q0uL8egRAzJlRV7Ed5nEcqZ1yE/UQeZJad3VmhgTSFE=
github.com/conduitio/conduit-schema-registry v0.2.2/go.mod h1:EmT4ylkz15LYddL6qU4wDX52n1Yp0aHvEDRIWOYYzFs=
github.com/conduitio/ecdysis v0.0.0-20241217205706-d372dbe18745 h1:du6u1lB9CxjDn+7Zw+ToxahhPcSyu/jEoFHp0f6iWHk=
github.com/conduitio/ecdysis v0.0.0-20241217205706-d372dbe18745/go.mod h1:k0i+Krn8g63HNFnGNnkf8YWf+Lg0KrHRRQtkE0I4MRE=
github.com/conduitio/ecdysis v0.0.0-20241218142415-9853ff79b597 h1:USx/cbKKwNBprSquCcfCnqKz3+dVU9Q7Wjijoh0lCBI=
github.com/conduitio/ecdysis v0.0.0-20241218142415-9853ff79b597/go.mod h1:k0i+Krn8g63HNFnGNnkf8YWf+Lg0KrHRRQtkE0I4MRE=
github.com/conduitio/yaml/v3 v3.3.0 h1:kbbaOSHcuH39gP4+rgbJGl6DSbLZcJgEaBvkEXJlCsI=
github.com/conduitio/yaml/v3 v3.3.0/go.mod h1:JNgFMOX1t8W4YJuRZOh6GggVtSMsgP9XgTw+7dIenpc=
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
Expand Down

0 comments on commit 370a638

Please sign in to comment.