diff --git a/pkg/config/config.go b/pkg/config/config.go index fe70208..61b50ac 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,7 +16,7 @@ type Repository struct { } type Configuration struct { - Domain string `json:"domain" validate:"required"` + Domain string `json:"domain,omitempty"` Pat string `json:"pat" validate:"required"` Organization string `json:"organization" validate:"required"` Repositories []Repository `json:"repositories" validate:"required"` @@ -45,6 +45,10 @@ func LoadConfiguration(src io.Reader) (*Configuration, error) { return nil, err } + if len(c.Domain) == 0 { + c.Domain = "dev.azure.com" + } + err = validate.New().Struct(c) if err != nil { return nil, err diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 12190d2..51d5ca4 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -41,6 +41,20 @@ const missingParamJson = ` } ` +const minimalJson = ` +{ + "pat": "foobar", + "organization": "xenitab", + "repositories": [ + { + "name": "gitops-deployment", + "project": "Lab", + "token": "foobar" + } + ] +} +` + func TestValidJson(t *testing.T) { reader := strings.NewReader(validJson) _, err := LoadConfiguration(reader) @@ -64,3 +78,15 @@ func TestMissingParam(t *testing.T) { t.Error("error should not be nil") } } + +func TestMinimalJson(t *testing.T) { + reader := strings.NewReader(minimalJson) + c, err := LoadConfiguration(reader) + if err != nil { + t.Errorf("could not parse json: %v", err) + } + + if c.Domain != "dev.azure.com" { + t.Errorf("default domain incorrect") + } +}