diff --git a/pkg/config/error.go b/pkg/config/error.go index c456fa9..24afa92 100644 --- a/pkg/config/error.go +++ b/pkg/config/error.go @@ -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" ) diff --git a/pkg/config/prometheus.go b/pkg/config/prometheus.go index 654949c..1a39192 100644 --- a/pkg/config/prometheus.go +++ b/pkg/config/prometheus.go @@ -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 { diff --git a/pkg/config/prometheus_test.go b/pkg/config/prometheus_test.go index fb06514..efabb40 100644 --- a/pkg/config/prometheus_test.go +++ b/pkg/config/prometheus_test.go @@ -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()) + }) + } } diff --git a/pkg/config/settings_test.go b/pkg/config/settings_test.go index 4489acd..068ad38 100644 --- a/pkg/config/settings_test.go +++ b/pkg/config/settings_test.go @@ -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) { diff --git a/pkg/diagnostic/catalog/catalog_test.go b/pkg/diagnostic/catalog/catalog_test.go index a37b51b..9e32e9e 100644 --- a/pkg/diagnostic/catalog/catalog_test.go +++ b/pkg/diagnostic/catalog/catalog_test.go @@ -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 }