Skip to content

Commit 790eba6

Browse files
committed
Add default value for domain
1 parent 2403986 commit 790eba6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Repository struct {
1616
}
1717

1818
type Configuration struct {
19-
Domain string `json:"domain" validate:"required"`
19+
Domain string `json:"domain,omitempty"`
2020
Pat string `json:"pat" validate:"required"`
2121
Organization string `json:"organization" validate:"required"`
2222
Repositories []Repository `json:"repositories" validate:"required"`
@@ -45,6 +45,10 @@ func LoadConfiguration(src io.Reader) (*Configuration, error) {
4545
return nil, err
4646
}
4747

48+
if len(c.Domain) == 0 {
49+
c.Domain = "dev.azure.com"
50+
}
51+
4852
err = validate.New().Struct(c)
4953
if err != nil {
5054
return nil, err

pkg/config/config_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ const missingParamJson = `
4141
}
4242
`
4343

44+
const minimalJson = `
45+
{
46+
"pat": "foobar",
47+
"organization": "xenitab",
48+
"repositories": [
49+
{
50+
"name": "gitops-deployment",
51+
"project": "Lab",
52+
"token": "foobar"
53+
}
54+
]
55+
}
56+
`
57+
4458
func TestValidJson(t *testing.T) {
4559
reader := strings.NewReader(validJson)
4660
_, err := LoadConfiguration(reader)
@@ -64,3 +78,15 @@ func TestMissingParam(t *testing.T) {
6478
t.Error("error should not be nil")
6579
}
6680
}
81+
82+
func TestMinimalJson(t *testing.T) {
83+
reader := strings.NewReader(minimalJson)
84+
c, err := LoadConfiguration(reader)
85+
if err != nil {
86+
t.Errorf("could not parse json: %v", err)
87+
}
88+
89+
if c.Domain != "dev.azure.com" {
90+
t.Errorf("default domain incorrect")
91+
}
92+
}

0 commit comments

Comments
 (0)