mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-07 00:18:45 +00:00
* Initial work. * Periodic push. * Fmt and start adding args to approve_policies cmd. * keep funcs for now. * Periodic push. * Periodic push. * fmt. * Move approve policies logic to project_command_runner. * update some tests * More test fixes. * update more tests. fix som logic. * more tests. add additional info to common data for custom templates. * fix apply with policies bug. update more tests/fmt * file perms * fix error parsing for conftest results. * Update more tests and linting. * update documentation. * Address no-fail case. Address comments. * Forgot changes. * fix markdown renderer * Fix policy fail logic. remove uneeded tmpl var * targeted policy approvals fix * Address PR comments. * empty commit to trigger build --------- Co-authored-by: PePe Amengual <jose.amengual@gmail.com> Co-authored-by: rkstrickland <ross.strickland@instacart.com> Co-authored-by: Dylan Page <dylan.page@autodesk.com>
123 lines
2.2 KiB
Go
123 lines
2.2 KiB
Go
package valid_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/runatlantis/atlantis/server/core/config/valid"
|
|
. "github.com/runatlantis/atlantis/testing"
|
|
)
|
|
|
|
func TestPoliciesConfig_HasTeamOwners(t *testing.T) {
|
|
cases := []struct {
|
|
description string
|
|
input valid.PolicySets
|
|
expResult bool
|
|
}{
|
|
{
|
|
description: "no team owners",
|
|
input: valid.PolicySets{
|
|
PolicySets: []valid.PolicySet{
|
|
{
|
|
Name: "policy1",
|
|
},
|
|
},
|
|
},
|
|
expResult: false,
|
|
},
|
|
{
|
|
description: "has top-level team owner",
|
|
input: valid.PolicySets{
|
|
Owners: valid.PolicyOwners{
|
|
Teams: []string{
|
|
"someteam",
|
|
},
|
|
},
|
|
PolicySets: []valid.PolicySet{
|
|
{
|
|
Name: "policy1",
|
|
},
|
|
},
|
|
},
|
|
expResult: true,
|
|
},
|
|
{
|
|
description: "has policy-level team owner",
|
|
input: valid.PolicySets{
|
|
PolicySets: []valid.PolicySet{
|
|
{
|
|
Name: "policy1",
|
|
Owners: valid.PolicyOwners{
|
|
Teams: []string{
|
|
"someteam",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expResult: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.description, func(t *testing.T) {
|
|
result := c.input.HasTeamOwners()
|
|
Equals(t, c.expResult, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPoliciesConfig_IsOwners(t *testing.T) {
|
|
user := "testuser"
|
|
userTeams := []string{"testuserteam"}
|
|
|
|
cases := []struct {
|
|
description string
|
|
input valid.PolicyOwners
|
|
expResult bool
|
|
}{
|
|
{
|
|
description: "user is not owner",
|
|
input: valid.PolicyOwners{
|
|
Users: []string{
|
|
"someotheruser",
|
|
},
|
|
Teams: []string{
|
|
"someotherteam",
|
|
},
|
|
},
|
|
expResult: false,
|
|
},
|
|
{
|
|
description: "user is owner",
|
|
input: valid.PolicyOwners{
|
|
Users: []string{
|
|
"testuser",
|
|
"someotheruser",
|
|
},
|
|
Teams: []string{
|
|
"someotherteam",
|
|
},
|
|
},
|
|
expResult: true,
|
|
},
|
|
{
|
|
description: "user is owner via team membership",
|
|
input: valid.PolicyOwners{
|
|
Users: []string{
|
|
"someotheruser",
|
|
},
|
|
Teams: []string{
|
|
"someotherteam",
|
|
"testuserteam",
|
|
},
|
|
},
|
|
expResult: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.description, func(t *testing.T) {
|
|
result := c.input.IsOwner(user, userTeams)
|
|
Equals(t, c.expResult, result)
|
|
})
|
|
}
|
|
}
|