Skip to content

Commit

Permalink
fix: all stages
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Haeberli committed Jul 18, 2023
1 parent 3ff7f01 commit f85b537
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 81 deletions.
Binary file modified momentum-backend/momentum-core
Binary file not shown.
39 changes: 18 additions & 21 deletions momentum-backend/tree/momentum-tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ func (n *Node) Apps() []*Node {

root := n.MomentumRoot()
apps := make([]*Node, 0)
for _, app := range root.Children {
if app.Kind == Directory {
apps = append(apps, app)
}
for _, app := range root.Directories() {
apps = append(apps, app)
}
return apps
}
Expand All @@ -37,11 +35,26 @@ func (n *Node) AllStages() []*Node {
apps := n.Apps()
stgs := make([]*Node, 0)
for _, app := range apps {
stgs = append(stgs, stages(app.Children, stgs)...)
fmt.Println("app", app.Path, app.Id)
stgs = append(stgs, app.stages()...)
}
return stgs
}

func (n *Node) stages() []*Node {

nodesStages := make([]*Node, 0)
for _, possibleStage := range n.Directories() {
fmt.Println(possibleStage.Id, ":", possibleStage.FullPath())
if possibleStage.Kind == Directory && !strings.HasPrefix(possibleStage.Path, META_PREFIX) {
childStages := possibleStage.stages()
nodesStages = append([]*Node{possibleStage}, childStages...)
}
}

return nodesStages
}

func (n *Node) IsStage() bool {

stages := n.AllStages()
Expand Down Expand Up @@ -92,22 +105,6 @@ func (n *Node) Deployment(deploymentId string) *Node {
return nil
}

func stages(parents []*Node, stgs []*Node) []*Node {

if len(parents) == 0 {
return stgs
}

for _, node := range parents {
if node.Kind == Directory && !strings.HasPrefix(node.Path, META_PREFIX) {
stgs = stages(node.Children, stgs)
stgs = append([]*Node{node}, stgs...)
}
}

return stgs
}

func deployments(stage *Node) []*Node {

files := stage.Files()
Expand Down
60 changes: 0 additions & 60 deletions momentum-backend/utils/filehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,9 @@ package utils_test

import (
"momentum-core/utils"
"strings"
"testing"
)

func TestBuildPath(t *testing.T) {

absoluteExpectedResult := "/from/root/append/suffix"
relativeExpectedResult := "./from/root/append/suffix"
relativeExpectedResult2 := "from/root/append/suffix"
fileSuffixExpectedResult := "/from/root/append/config.yml"

absoluteBase := "/from/root/"
absoluteBase2 := "/from/root"
relativeBase := "from/root/"
relativeBase2 := "./from/root/"
relativeBase3 := "from/root"

suffix := "append/suffix"
suffix2 := "append/suffix/"
suffix3 := "/append/suffix" // This is convenience and might be misleading for user -> supplying absolute path as suffix and accepting
suffix4 := "/append/suffix/" // This is convenience and might be misleading for user -> supplying absolute path as suffix and accepting

fileSuffix := "append/config.yml"

absolutePaths := []string{absoluteBase, absoluteBase2}
relativePaths := []string{relativeBase, relativeBase2, relativeBase3}
suffixes := []string{suffix, suffix2, suffix3, suffix4}
fileSuffixes := []string{fileSuffix}

for _, ap := range absolutePaths {
for _, s := range suffixes {
p := utils.BuildPath(ap, s)
if absoluteExpectedResult != p {
t.Error("Test failed with", ap, s, p)
}
}
}

for _, rp := range relativePaths {

check := relativeExpectedResult2
if strings.Index(strings.Trim(rp, " "), ".") == 0 {
check = relativeExpectedResult
}

for _, s := range suffixes {
p := utils.BuildPath(rp, s)
if check != p {
t.Error("Test failed with", rp, s, p)
}
}
}

for _, ap := range absolutePaths {
for _, s := range fileSuffixes {
p := utils.BuildPath(ap, s)
if fileSuffixExpectedResult != p {
t.Error("Test failed with", ap, s, p)
}
}
}
}

func TestFileEmpty(t *testing.T) {
testFile := "./testdata/emptyfile.yaml"

Expand Down

0 comments on commit f85b537

Please sign in to comment.