summaryrefslogtreecommitdiff
path: root/go/internal/config/config_test.go
blob: 0a5c842f26cb1e6c4c645b8c1d1db44cb5033a96 (plain)
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
37
package config

import (
	"fmt"
	"testing"
)

func TestConfigLogFile(t *testing.T) {
	testRoot := "/foo/bar"
	testCases := []struct {
		yaml   string
		path   string
		format string
	}{
		{path: "/foo/bar/gitlab-shell.log", format: "text"},
		{yaml: "log_file: my-log.log", path: "/foo/bar/my-log.log", format: "text"},
		{yaml: "log_file: /qux/my-log.log", path: "/qux/my-log.log", format: "text"},
		{yaml: "log_format: json", path: "/foo/bar/gitlab-shell.log", format: "json"},
	}

	for _, tc := range testCases {
		t.Run(fmt.Sprintf("yaml input: %q", tc.yaml), func(t *testing.T) {
			cfg := Config{RootDir: testRoot}
			if err := parseConfig([]byte(tc.yaml), &cfg); err != nil {
				t.Fatal(err)
			}

			if cfg.LogFile != tc.path {
				t.Fatalf("expected %q, got %q", tc.path, cfg.LogFile)
			}

			if cfg.LogFormat != tc.format {
				t.Fatalf("expected %q, got %q", tc.format, cfg.LogFormat)
			}
		})
	}
}