diff --git a/go.mod b/go.mod index 9f1a5e2..da89e43 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,15 @@ require github.com/go-resty/resty/v2 v2.7.0 require ( github.com/VividCortex/ewma v1.2.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.15.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect golang.org/x/sys v0.6.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( @@ -19,6 +22,7 @@ require ( github.com/cheggaaa/pb/v3 v3.1.4 github.com/google/martian v2.1.0+incompatible github.com/sirupsen/logrus v1.9.3 + github.com/stretchr/testify v1.9.0 golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 62fbd76..9d95c74 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,7 @@ github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBa github.com/cheggaaa/pb/v3 v3.1.4 h1:DN8j4TVVdKu3WxVwcRKu0sG00IIU6FewoABZzXbRQeo= github.com/cheggaaa/pb/v3 v3.1.4/go.mod h1:6wVjILNBaXMs8c21qRiaUM8BR82erfgau1DQ4iUXmSA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= @@ -19,6 +20,7 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -26,6 +28,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM= golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -42,3 +46,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/harness/git_details.go b/harness/git_details.go index d2af433..1bc1f9e 100644 --- a/harness/git_details.go +++ b/harness/git_details.go @@ -40,7 +40,7 @@ func GetServiceFilePath(gitX bool, customGitDetailsFilePath string, p Project, s func GetEnvironmentFilePath(gitX bool, customGitDetailsFilePath string, p Project, env EnvironmentClass) string { if len(customGitDetailsFilePath) == 0 { if gitX { - return fmt.Sprintf(".harness/orgs/%s/projects/%s/environments/%s.yaml", string(p.OrgIdentifier), p.Identifier, env.Identifier) + return fmt.Sprintf(".harness/orgs/%s/projects/%s/envs/%s/%s.yaml", string(p.OrgIdentifier), p.Identifier, getEnvType(env), env.Identifier) } return "environments/" + string(p.OrgIdentifier) + "/" + p.Identifier + "/" + env.Identifier + ".yaml" } else { @@ -51,7 +51,7 @@ func GetEnvironmentFilePath(gitX bool, customGitDetailsFilePath string, p Projec func GetInfrastructureFilePath(gitX bool, customGitDetailsFilePath string, p Project, env EnvironmentClass, infraDef Infrastructure) string { if len(customGitDetailsFilePath) == 0 { if gitX { - return fmt.Sprintf(".harness/orgs/%s/projects/%s/environments/%s/infrastructures/%s.yaml", string(p.OrgIdentifier), p.Identifier, env.Identifier, infraDef.Identifier) + return fmt.Sprintf(".harness/orgs/%s/projects/%s/envs/%s/%s/infras/%s.yaml", string(p.OrgIdentifier), p.Identifier, getEnvType(env), env.Identifier, infraDef.Identifier) } return "environments/" + string(p.OrgIdentifier) + "/" + p.Identifier + "/" + env.Identifier + "-" + infraDef.Identifier + ".yaml" } else { @@ -94,3 +94,14 @@ func GetInputsetFilePath(gitX bool, customGitDetailsFilePath string, p Project, return customGitDetailsFilePath + "/" + is.PipelineIdentifier + "/" + is.Identifier + ".yaml" } } + +func getEnvType(env EnvironmentClass) string { + switch env.Type { + case "Production": + return "production" + case "PreProduction": + return "pre_production" + default: + return "unknown" + } +} diff --git a/harness/git_details_test.go b/harness/git_details_test.go new file mode 100644 index 0000000..fb26620 --- /dev/null +++ b/harness/git_details_test.go @@ -0,0 +1,31 @@ +package harness + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_GetEnvironmentFilePath_GitX(t *testing.T) { + path := GetEnvironmentFilePath(true, "", Project{ + Identifier: "pId", + OrgIdentifier: "orgId", + }, EnvironmentClass{ + Identifier: "envId", + Type: "PreProduction", + }) + assert.Equal(t, ".harness/orgs/orgId/projects/pId/envs/pre_production/envId.yaml", path) +} + +func Test_GetInfrastructureFilePath_GitX(t *testing.T) { + path := GetInfrastructureFilePath(true, "", Project{ + Identifier: "pId", + OrgIdentifier: "orgId", + }, EnvironmentClass{ + Identifier: "envId", + Type: "PreProduction", + }, Infrastructure{ + Identifier: "infraId", + }) + assert.Equal(t, ".harness/orgs/orgId/projects/pId/envs/pre_production/envId/infras/infraId.yaml", path) +}