diff --git a/momentum-backend/momentum-core b/momentum-backend/momentum-core index e8e9b11..138aee0 100755 Binary files a/momentum-backend/momentum-core and b/momentum-backend/momentum-core differ diff --git a/momentum-backend/tree/momentum-tree.go b/momentum-backend/tree/momentum-tree.go index 3f745c3..1cdc958 100644 --- a/momentum-backend/tree/momentum-tree.go +++ b/momentum-backend/tree/momentum-tree.go @@ -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 } @@ -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() @@ -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() diff --git a/momentum-backend/utils/filehandler_test.go b/momentum-backend/utils/filehandler_test.go index 6ae738c..7dafe95 100644 --- a/momentum-backend/utils/filehandler_test.go +++ b/momentum-backend/utils/filehandler_test.go @@ -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"