cerrado @ 4ea63e98cc999ab05d1ac98b64875d7413e86972

 1// go:build unit
 2package config
 3
 4import (
 5	"strings"
 6	"testing"
 7
 8	"github.com/google/go-cmp/cmp"
 9)
10
11func TestFileParsing(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}