aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/config_test.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-04 23:16:38 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-04 23:17:02 +0200
commit8a2461aa05895cc7828bc9619b50fa5dee5ed1f4 (patch)
tree86c6848d9c9a7d7b2d272fa43af66350d2cd1d0e /pkg/config/config_test.go
parent3fb9c66ffa0bf87cbd7cc1b5f4129f3447e94c13 (diff)
downloadcerrado-8a2461aa05895cc7828bc9619b50fa5dee5ed1f4.tar.gz
cerrado-8a2461aa05895cc7828bc9619b50fa5dee5ed1f4.tar.bz2
cerrado-8a2461aa05895cc7828bc9619b50fa5dee5ed1f4.zip
feat: Add config parsing
Diffstat (limited to 'pkg/config/config_test.go')
-rw-r--r--pkg/config/config_test.go56
1 files changed, 56 insertions, 0 deletions
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)
+ }
+
+ })
+
+ }
+}