1// go:build unit
2package config
3
4import (
5 "strings"
6 "testing"
7
8 "github.com/google/go-cmp/cmp"
9)
10
11func TestConfig(t *testing.T) {
12 testCases := []struct {
13 name string
14 config string
15 expectedConfig *Configuration
16 }{
17 {
18 name: "minimal scan",
19 config: `scan "/srv/git"`,
20 expectedConfig: &Configuration{
21 Scan: &Scan{
22 Public: true,
23 Path: "/srv/git",
24 },
25 },
26 },
27 {
28 name: "complete scan",
29 config: `scan "/srv/git" {
30 public false
31}`,
32 expectedConfig: &Configuration{
33 Scan: &Scan{
34 Public: false,
35 Path: "/srv/git",
36 },
37 },
38 },
39 }
40
41 for _, tc := range testCases {
42 t.Run(tc.name, func(t *testing.T) {
43 r := strings.NewReader(tc.config)
44 config, err := Parse(r)
45 if err != nil {
46 t.Fatalf("Error parsing config %s", err.Error())
47 }
48
49 if diff := cmp.Diff(tc.expectedConfig, config); diff != "" {
50 t.Errorf("Wrong result given - wanted + got\n %s", diff)
51 }
52
53 })
54
55 }
56}