Skip to content

Commit

Permalink
Add default value for domain
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed Jul 9, 2020
1 parent 2403986 commit 790eba6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
}

0 comments on commit 790eba6

Please sign in to comment.