Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrennz committed Sep 24, 2024
1 parent 934dcee commit e4d20cd
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 94 deletions.
24 changes: 12 additions & 12 deletions pkg/config/error.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package config

const (
ErrNoLifecycleStageMsg = "missing Lifecycle Stage"
ErrNoEnvFileMsg = "missing Env File"
ErrNoKeyFileMsg = "missing Key File"
ErrNoCloudZeroHostMsg = "missing CloudZero Host"
ErrNoAccountIDMsg = "missing AWS Account ID"
ErrNoClusterNameMsg = "missing Cluster Name"
ErrNoRegionMsg = "missing AWS Region"
ErrNoSecretFilePathMsg = "missing Secret File"
ErrNoAgentVersionMsg = "missing Agent Version"
ErrNoChartVersionMsg = "missing Chart Version"
ErrNoScrapeConfigLocationMsg = "missing Scrape Config Location"
ErrNoKubeStateMetricsServiceEndpointMsg = "missing Kube State Metrics Service Endpoint"
ErrNoLifecycleStageMsg = "missing Lifecycle Stage"
ErrNoEnvFileMsg = "missing Env File"
ErrNoKeyFileMsg = "missing Key File"
ErrNoCloudZeroHostMsg = "missing CloudZero Host"
ErrNoAccountIDMsg = "missing AWS Account ID"
ErrNoClusterNameMsg = "missing Cluster Name"
ErrNoRegionMsg = "missing AWS Region"
ErrNoSecretFilePathMsg = "missing Secret File"
ErrNoAgentVersionMsg = "missing Agent Version"
ErrNoChartVersionMsg = "missing Chart Version"
ErrNoScrapeConfigLocationMsg = "missing Scrape Config Location"
ErrNoKubeStateMetricsServiceEndpointMsg = "missing Kube State Metrics Service Endpoint"
)
6 changes: 3 additions & 3 deletions pkg/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type Prometheus struct {
Executable string `yaml:"executable" default:"/bin/prometheus" env:"PROMETHEUS_EXECUTABLE" env-description:"Prometheus Executable Path"`
KubeStateMetricsServiceEndpoint string `yaml:"kube_state_metrics_service_endpoint" env:"KMS_EP_URL" required:"true" env-description:"Kube State Metrics Service Endpoint"`
Configurations []string `yaml:"configurations"`
Executable string `yaml:"executable" default:"/bin/prometheus" env:"PROMETHEUS_EXECUTABLE" env-description:"Prometheus Executable Path"`
KubeStateMetricsServiceEndpoint string `yaml:"kube_state_metrics_service_endpoint" env:"KMS_EP_URL" required:"true" env-description:"Kube State Metrics Service Endpoint"`
Configurations []string `yaml:"configurations"`
}

func (s *Prometheus) Validate() error {
Expand Down
92 changes: 46 additions & 46 deletions pkg/config/prometheus_test.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package config_test

import (
"os"
"testing"
"os"
"testing"

"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

func TestPrometheus_Validate(t *testing.T) {
wd, err := os.Getwd()
assert.NoError(t, err)
scrapeConfigFile := wd + "/testdata/prometheus.yml"
tests := []struct {
name string
prom config.Prometheus
expected error
}{
{
name: "ValidPrometheus",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: nil,
},
{
name: "MissingKubeStateMetricsServiceEndpoint",
prom: config.Prometheus{
Configurations: []string{scrapeConfigFile},
},
expected: errors.New(config.ErrNoKubeStateMetricsServiceEndpointMsg),
},
{
name: "MissingScrapeConfigLocation",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
},
expected: nil,
},
}
wd, err := os.Getwd()
assert.NoError(t, err)
scrapeConfigFile := wd + "/testdata/prometheus.yml"
tests := []struct {
name string
prom config.Prometheus
expected error
}{
{
name: "ValidPrometheus",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
Configurations: []string{scrapeConfigFile},
},
expected: nil,
},
{
name: "MissingKubeStateMetricsServiceEndpoint",
prom: config.Prometheus{
Configurations: []string{scrapeConfigFile},
},
expected: errors.New(config.ErrNoKubeStateMetricsServiceEndpointMsg),
},
{
name: "MissingScrapeConfigLocation",
prom: config.Prometheus{
KubeStateMetricsServiceEndpoint: kmsServiceEndpoint,
},
expected: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.prom.Validate()
if tt.expected == nil {
assert.NoError(t, err)
return
}
assert.Equal(t, tt.expected.Error(), err.Error())
})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.prom.Validate()
if tt.expected == nil {
assert.NoError(t, err)
return
}
assert.Equal(t, tt.expected.Error(), err.Error())
})
}
}
2 changes: 1 addition & 1 deletion pkg/config/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
apiHost = "https://api.cloudzero.com"
apiKey = "my-cloudzero-token"

kmsServiceEndpoint = "http://kube-state-metrics:8080"
kmsServiceEndpoint = "http://kube-state-metrics:8080"
)

func TestSettings_NewSettings(t *testing.T) {
Expand Down
64 changes: 32 additions & 32 deletions pkg/diagnostic/catalog/catalog_test.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
package catalog_test

import (
"context"
"testing"
"context"
"testing"

"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/catalog"
"github.com/stretchr/testify/assert"
"github.com/cloudzero/cloudzero-agent-validator/pkg/config"
"github.com/cloudzero/cloudzero-agent-validator/pkg/diagnostic/catalog"
"github.com/stretchr/testify/assert"
)

func TestRegistry_Get(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test getting providers with existing IDs
providers := r.Get(config.DiagnosticAPIKey, config.DiagnosticK8sVersion)
assert.Len(t, providers, 2)
// Test getting providers with existing IDs
providers := r.Get(config.DiagnosticAPIKey, config.DiagnosticK8sVersion)
assert.Len(t, providers, 2)

// Test getting providers with non-existing IDs
providers = r.Get("non-existing-id")
assert.Empty(t, providers)
// Test getting providers with non-existing IDs
providers = r.Get("non-existing-id")
assert.Empty(t, providers)

// Test getting providers with empty IDs
providers = r.Get()
assert.Empty(t, providers)
// Test getting providers with empty IDs
providers = r.Get()
assert.Empty(t, providers)
}

func TestRegistry_Has(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test checking for existing ID
has := r.Has(config.DiagnosticAPIKey)
assert.True(t, has)
// Test checking for existing ID
has := r.Has(config.DiagnosticAPIKey)
assert.True(t, has)

// Test checking for non-existing ID
has = r.Has("non-existing-id")
assert.False(t, has)
// Test checking for non-existing ID
has = r.Has("non-existing-id")
assert.False(t, has)
}

func TestRegistry_List(t *testing.T) {
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)
ctx := context.Background()
c := &config.Settings{}
r := catalog.NewCatalog(ctx, c)

// Test listing providers
providers := r.List()
assert.Len(t, providers, 6) // Update the expected length to 6
// Test listing providers
providers := r.List()
assert.Len(t, providers, 6) // Update the expected length to 6
}

0 comments on commit e4d20cd

Please sign in to comment.