ajhahn.de
← eeco
Go 39 lines
package config

import (
	"path/filepath"
	"reflect"
	"strings"
	"testing"
)

func TestLoad_AttributionPatternRepeatable(t *testing.T) {
	root := newRepo(t)
	wsDir := filepath.Join(root, "tester", DefaultWorkspace)
	write(t, wsDir, "config.local", strings.Join([]string{
		"attribution_pattern=FIRST-MARK",
		`attribution_pattern = "SECOND MARK"`,
		"attribution_pattern=", // empty value ignored, cannot disable the gate
	}, "\n"))

	cfg, err := Load(root, "")
	if err != nil {
		t.Fatal(err)
	}
	want := []string{"FIRST-MARK", "SECOND MARK"}
	if !reflect.DeepEqual(cfg.AttributionPatterns, want) {
		t.Errorf("AttributionPatterns = %v, want %v", cfg.AttributionPatterns, want)
	}
}

func TestLoad_AttributionPatternDefaultEmpty(t *testing.T) {
	root := newRepo(t)
	cfg, err := Load(root, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(cfg.AttributionPatterns) != 0 {
		t.Errorf("default AttributionPatterns = %v, want empty", cfg.AttributionPatterns)
	}
}