forked from runatlantis/atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add flag to allow the user disable the autodiscover
- Loading branch information
Marcelo Medeiros
committed
Oct 13, 2023
1 parent
27010d3
commit 1b9ca74
Showing
16 changed files
with
542 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package raw | ||
|
||
import ( | ||
"github.com/runatlantis/atlantis/server/core/config/valid" | ||
) | ||
|
||
type Autodiscover struct { | ||
Enabled *bool `yaml:"enabled,omitempty"` | ||
} | ||
|
||
func (a Autodiscover) ToValid() valid.Autodiscover { | ||
var v valid.Autodiscover | ||
|
||
if a.Enabled == nil { | ||
v.Enabled = true | ||
} else { | ||
v.Enabled = *a.Enabled | ||
} | ||
|
||
return v | ||
} | ||
|
||
func (a Autodiscover) Validate() error { | ||
return nil | ||
} | ||
|
||
// DefaultAutoDiscover returns the default autodiscover config. | ||
func DefaultAutoDiscover() valid.Autodiscover { | ||
return valid.Autodiscover{ | ||
Enabled: valid.DefaultAutoDiscoverEnabled, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package raw_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/runatlantis/atlantis/server/core/config/raw" | ||
"github.com/runatlantis/atlantis/server/core/config/valid" | ||
. "github.com/runatlantis/atlantis/testing" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestAutoDiscover_UnmarshalYAML(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
input string | ||
exp raw.Autodiscover | ||
}{ | ||
{ | ||
description: "omit unset fields", | ||
input: "", | ||
exp: raw.Autodiscover{ | ||
Enabled: nil, | ||
}, | ||
}, | ||
{ | ||
description: "enabled true", | ||
input: ` | ||
enabled: true | ||
`, | ||
exp: raw.Autodiscover{ | ||
Enabled: Bool(true), | ||
}, | ||
}, | ||
{ | ||
description: "enabled false", | ||
input: ` | ||
enabled: false | ||
`, | ||
exp: raw.Autodiscover{ | ||
Enabled: Bool(false), | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
var a raw.Autodiscover | ||
err := yaml.UnmarshalStrict([]byte(c.input), &a) | ||
Ok(t, err) | ||
Equals(t, c.exp, a) | ||
}) | ||
} | ||
} | ||
|
||
func TestAutodiscover_Validate(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
input raw.Autodiscover | ||
}{ | ||
{ | ||
description: "nothing set", | ||
input: raw.Autodiscover{}, | ||
}, | ||
{ | ||
description: "enabled false", | ||
input: raw.Autodiscover{ | ||
Enabled: Bool(false), | ||
}, | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
Ok(t, c.input.Validate()) | ||
}) | ||
} | ||
} | ||
|
||
func TestAutodiscover_ToValid(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
input raw.Autodiscover | ||
exp valid.Autodiscover | ||
}{ | ||
{ | ||
description: "nothing set", | ||
input: raw.Autodiscover{}, | ||
exp: valid.Autodiscover{ | ||
Enabled: true, | ||
}, | ||
}, | ||
{ | ||
description: "enabled false", | ||
input: raw.Autodiscover{ | ||
Enabled: Bool(false), | ||
}, | ||
exp: valid.Autodiscover{ | ||
Enabled: false, | ||
}, | ||
}, | ||
{ | ||
description: "enabled true", | ||
input: raw.Autodiscover{ | ||
Enabled: Bool(true), | ||
}, | ||
exp: valid.Autodiscover{ | ||
Enabled: true, | ||
}, | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
Equals(t, c.exp, c.input.ToValid()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.