mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-29 06:18:24 +00:00
Previously, if you were using project names and you had two projects with the same directory and workspace but different workflows, running "atlantis apply" would fail. This was because we weren't figuring out what the project name was for each pending plan. This change fixes this by extracting the project name from the planfile. We also handle /'s in the project name by substituting them with '::'. This allows us to convert them back to /'s when we're figuring out the project names from the filenames. It's safe to do this because : isn't an allowed character for project names. We also remove a final substitution of invalid filename characters because we rely on the validation of the project names instead which happens when validating the atlantis.yaml file.
96 lines
1.8 KiB
Go
96 lines
1.8 KiB
Go
package runtime_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/runatlantis/atlantis/server/events/runtime"
|
|
. "github.com/runatlantis/atlantis/testing"
|
|
)
|
|
|
|
func TestGetPlanFilename(t *testing.T) {
|
|
cases := []struct {
|
|
workspace string
|
|
projectName string
|
|
exp string
|
|
}{
|
|
{
|
|
"workspace",
|
|
"",
|
|
"workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project",
|
|
"project-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project/with/slash",
|
|
"project::with::slash-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project with space",
|
|
"project with space-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace😀",
|
|
"project😀",
|
|
"project😀-workspace😀.tfplan",
|
|
},
|
|
// Previously we replaced invalid chars with -'s, however we now
|
|
// rely on validation of the atlantis.yaml file to ensure the name's
|
|
// don't contain chars that need to be url encoded. So now these
|
|
// chars shouldn't get replaced.
|
|
{
|
|
"default",
|
|
`all.invalid.chars \/"*?<>`,
|
|
"all.invalid.chars \\::\"*?<>-default.tfplan",
|
|
},
|
|
}
|
|
|
|
for i, c := range cases {
|
|
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
|
Equals(t, c.exp, runtime.GetPlanFilename(c.workspace, c.projectName))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestProjectNameFromPlanfile(t *testing.T) {
|
|
cases := []struct {
|
|
workspace string
|
|
filename string
|
|
exp string
|
|
}{
|
|
{
|
|
"workspace",
|
|
"workspace.tfplan",
|
|
"",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project-workspace.tfplan",
|
|
"project",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project-workspace-workspace.tfplan",
|
|
"project-workspace",
|
|
},
|
|
{
|
|
"workspace",
|
|
"project::with::slashes::-workspace.tfplan",
|
|
"project/with/slashes/",
|
|
},
|
|
}
|
|
|
|
for i, c := range cases {
|
|
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
|
act, err := runtime.ProjectNameFromPlanfile(c.workspace, c.filename)
|
|
Ok(t, err)
|
|
Equals(t, c.exp, act)
|
|
})
|
|
}
|
|
}
|