mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-04 04:38:38 +00:00
* fix(deps): update module gopkg.in/yaml.v2 to v3 in go.mod * chore: Upgrade to go-yaml v3 * Fix comment --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
149 lines
2.4 KiB
Go
149 lines
2.4 KiB
Go
package raw_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/runatlantis/atlantis/server/core/config/raw"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMetrics_Unmarshal(t *testing.T) {
|
|
t.Run("yaml", func(t *testing.T) {
|
|
|
|
rawYaml := `
|
|
statsd:
|
|
host: 127.0.0.1
|
|
port: 8125
|
|
prometheus:
|
|
endpoint: /metrics
|
|
`
|
|
|
|
var result raw.Metrics
|
|
|
|
err := unmarshalString(rawYaml, &result)
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
rawJSON := `
|
|
{
|
|
"statsd": {
|
|
"host": "127.0.0.1",
|
|
"port": "8125"
|
|
},
|
|
"prometheus": {
|
|
"endpoint": "/metrics"
|
|
}
|
|
}
|
|
`
|
|
|
|
var result raw.Metrics
|
|
|
|
err := json.Unmarshal([]byte(rawJSON), &result)
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
func TestMetrics_Validate_Success(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
description string
|
|
subject raw.Metrics
|
|
}{
|
|
{
|
|
description: "success with stats config",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Host: "127.0.0.1",
|
|
Port: "8125",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "success with stats config using hostname",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Host: "localhost",
|
|
Port: "8125",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "missing stats",
|
|
},
|
|
{
|
|
description: "success with prometheus config",
|
|
subject: raw.Metrics{
|
|
Prometheus: &raw.Prometheus{
|
|
Endpoint: "/metrics",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "success with both configs",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Host: "127.0.0.1",
|
|
Port: "8125",
|
|
},
|
|
Prometheus: &raw.Prometheus{
|
|
Endpoint: "/metrics",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.description, func(t *testing.T) {
|
|
assert.NoError(t, c.subject.Validate())
|
|
})
|
|
}
|
|
|
|
}
|
|
func TestMetrics_Validate_Error(t *testing.T) {
|
|
cases := []struct {
|
|
description string
|
|
subject raw.Metrics
|
|
}{
|
|
{
|
|
description: "missing host",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Port: "8125",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "missing port",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Host: "127.0.0.1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "invalid port",
|
|
subject: raw.Metrics{
|
|
Statsd: &raw.Statsd{
|
|
Host: "127.0.0.1",
|
|
Port: "string",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "invalid endpoint",
|
|
subject: raw.Metrics{
|
|
Prometheus: &raw.Prometheus{
|
|
Endpoint: "",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.description, func(t *testing.T) {
|
|
assert.Error(t, c.subject.Validate())
|
|
})
|
|
}
|
|
}
|