From 8a2461aa05895cc7828bc9619b50fa5dee5ed1f4 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 4 May 2024 23:16:38 +0200 Subject: feat: Add config parsing --- pkg/config/config_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pkg/config/config_test.go (limited to 'pkg/config/config_test.go') diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go new file mode 100644 index 0000000..c8cd887 --- /dev/null +++ b/pkg/config/config_test.go @@ -0,0 +1,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) + } + + }) + + } +} -- cgit v1.2.3