File: config_test.go

package info (click to toggle)
prometheus-script-exporter 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 336 kB
  • sloc: makefile: 51; sh: 41
file content (36 lines) | stat: -rw-r--r-- 926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package config

import (
	"testing"

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

func TestNewSafeConfig(t *testing.T) {
	t.Run("should load configuration", func(t *testing.T) {
		sc := NewSafeConfig(prometheus.NewRegistry())
		err := sc.ReloadConfig("./testdata/config-valid.yaml", nil)

		require.NoError(t, err)
		require.NotNil(t, sc.C)

		t.Run("should return script", func(t *testing.T) {
			script := sc.C.GetScript("output")
			require.NotNil(t, script)
			require.Equal(t, "output", script.Name)
		})

		t.Run("should return nil if script is not found", func(t *testing.T) {
			script := sc.C.GetScript("invalid")
			require.Nil(t, script)
		})
	})

	t.Run("should return error for invalid configuration", func(t *testing.T) {
		sc := NewSafeConfig(prometheus.NewRegistry())
		err := sc.ReloadConfig("./testdata/config-invalid.yaml", nil)

		require.Error(t, err)
	})
}