aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/config_test.go
blob: c8cd8876055e2cabe66e1ee574b5c36df358efcb (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// go:build unit
package config

import (
	"strings"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestConfig(t *testing.T) {
	testCases := []struct {
		name           string
		config         string
		expectedConfig *Configuration
	}{
		{
			name:   "minimal scan",
			config: `scan "/srv/git"`,
			expectedConfig: &Configuration{
				Scan: &Scan{
					Public: true,
					Path:   "/srv/git",
				},
			},
		},
		{
			name: "complete scan",
			config: `scan "/srv/git" {
	public false
}`,
			expectedConfig: &Configuration{
				Scan: &Scan{
					Public: false,
					Path:   "/srv/git",
				},
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			r := strings.NewReader(tc.config)
			config, err := Parse(r)
			if err != nil {
				t.Fatalf("Error parsing config %s", err.Error())
			}

			if diff := cmp.Diff(tc.expectedConfig, config); diff != "" {
				t.Errorf("Wrong result given - wanted + got\n %s", diff)
			}

		})

	}
}