Skip to content

Commit

Permalink
fix: adding tests for default config
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Feb 5, 2025
1 parent acb77c5 commit 29db309
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ linters-settings:

govet:
# report about shadowed variables
check-shadowing: false
shadow: false

gofmt:
# simplify code: gofmt with `-s` option, true by default
Expand Down
14 changes: 12 additions & 2 deletions api/v1alpha1/nats_config_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"github.com/zeiss/pkg/utilx"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -12,8 +13,17 @@ const (
)

// New returns a new Config object.
func New() Config {
return Config{}
func New() *Config {
return &Config{}
}

// Default returns the default configuration.
func Default() *Config {
cfg := New()

utilx.SetDefaults(cfg)

return cfg
}

// Config ...
Expand Down
22 changes: 22 additions & 0 deletions api/v1alpha1/nats_config_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v1alpha1_test

import (
"testing"

"github.com/zeiss/natz-operator/api/v1alpha1"

"github.com/stretchr/testify/require"
)

func TestDefault(t *testing.T) {
t.Parallel()

got := v1alpha1.Default()
want := &v1alpha1.Config{
Host: "0.0.0.0",
Port: 4222,
HTTPPort: 8222,
}

require.Equal(t, want, got)
}
15 changes: 15 additions & 0 deletions controllers/natsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (r *NatsConfigReconciler) reconcileConfig(ctx context.Context, obj *natsv1a
return err
}

// defaultConfig := natsv1alpha1.Default()

config := obj.Spec.Config

config.Resolver = &natsv1alpha1.Resolver{
Expand All @@ -132,6 +134,19 @@ func (r *NatsConfigReconciler) reconcileConfig(ctx context.Context, obj *natsv1a
systemAccount.Status.PublicKey: systemAccount.Status.JWT,
}

// for _, gateway := range obj.Spec.Gateways {
// gw := natsv1alpha1.GatewayEntry{
// Name: gateway.Name,
// URLS: []string{},
// }

// if utilx.Empty(config.Gateway) {
// config.Gateway = &natsv1alpha1.Gateway{}
// }

// config.Gateway.Gateways = append(config.Gateway.Gateways, gw)
// }

b, err := json.Marshal(config)
if err != nil {
return err
Expand Down

0 comments on commit 29db309

Please sign in to comment.