// go:build unit package config import ( "strings" "testing" "github.com/google/go-cmp/cmp" ) func TestFileParsing(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) } }) } }