Skip to content

Commit

Permalink
use ignore validate tag
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Nov 19, 2024
1 parent 1466753 commit b11c00c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pkg/utils/activity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
type Config struct {
Enabled bool `default:"false"`
Topic string `required:"false"`
Network Network `required:"false"`
Network Network `required:"false" validate:"ignore"`
AggregationWindow time.Duration `split_words:"true" default:"5m"`
Testing bool `default:"false"`
Ensign ensign.Config
Testing bool `default:"false" `
Ensign ensign.Config `validate:"ignore"`
}

func (c Config) Validate() (err error) {
Expand All @@ -22,11 +22,11 @@ func (c Config) Validate() (err error) {
err = errors.Join(err, ErrMissingTopic)
}

if verr := c.Network.IsValid(); verr != nil {
if verr := c.Network.Validate(); verr != nil {
err = errors.Join(err, verr)
}

if verr := c.Ensign.IsValid(); verr != nil {
if verr := c.Ensign.Validate(); verr != nil {
err = errors.Join(err, verr)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/activity/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func (n Network) String() string {
}

// Check if the network is valid.
// NOTE: this method must be named IsValid and not Validate to prevent confire from
// NOTE: this method must be named Validate and not Validate to prevent confire from
// calling this function during validation. Configurations that use a Network should
// manually call IsValid in their Validation method.
func (n Network) IsValid() error {
// manually call Validate in their Validation method.
func (n Network) Validate() error {
if n == UnknownNetwork {
return ErrUnknownNetwork
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/ensign/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type Config struct {
}

// Validate that the ensign config is ready for connection.
// NOTE: This must be IsValid() and not Validate() to prevent confire from calling
// NOTE: This must be Validate() and not Validate() to prevent confire from calling
// this function to check if the configuration is valid. Configurations that embed an
// ensign configuration should manually call IsValid in their Validation method.
func (c Config) IsValid() (err error) {
// ensign configuration should manually call Validate in their Validation method.
func (c Config) Validate() (err error) {
if c.Testing {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/utils/ensign/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ func TestValidate(t *testing.T) {
}

// Should error if client id is missing.
require.ErrorIs(t, config.IsValid(), ensign.ErrMissingClientID, "expected missing client id error")
require.ErrorIs(t, config.Validate(), ensign.ErrMissingClientID, "expected missing client id error")

// Should error if client secret is missing.
config.ClientID = "client-id"
config.ClientSecret = ""
require.ErrorIs(t, config.IsValid(), ensign.ErrMissingClientSecret, "expected missing client secret error")
require.ErrorIs(t, config.Validate(), ensign.ErrMissingClientSecret, "expected missing client secret error")

// Should error if endpoint is missing.
config.ClientSecret = "client-secret"
config.Endpoint = ""
require.ErrorIs(t, config.IsValid(), ensign.ErrMissingEndpoint, "expected missing endpoint error")
require.ErrorIs(t, config.Validate(), ensign.ErrMissingEndpoint, "expected missing endpoint error")

// Should error if auth url is missing.
config.Endpoint = "ensign.rotational.app:443"
config.AuthURL = ""
require.ErrorIs(t, config.IsValid(), ensign.ErrMissingAuthURL, "expected missing auth url error")
require.ErrorIs(t, config.Validate(), ensign.ErrMissingAuthURL, "expected missing auth url error")

// Should not error if all required fields are present.
config.AuthURL = "https://auth.rotational.app"
require.NoError(t, config.IsValid(), "expected no error for valid configuration")
require.NoError(t, config.Validate(), "expected no error for valid configuration")
}

0 comments on commit b11c00c

Please sign in to comment.