Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/un 2ify #930

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cmd/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"os"

engine "github.com/klothoplatform/klotho/pkg/engine2"
engine "github.com/klothoplatform/klotho/pkg/engine"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/dot.go → pkg/construct/dot.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/graph.go → pkg/construct/graph.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"crypto/sha256"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"sort"
Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/graph_io.go → pkg/construct/graph_io.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"testing"

"github.com/dominikbraun/graph"
"github.com/klothoplatform/klotho/pkg/construct2"
"github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
)

func AssertGraphEqual(t *testing.T, expect, actual construct2.Graph, message string, args ...any) {
func AssertGraphEqual(t *testing.T, expect, actual construct.Graph, message string, args ...any) {
assert := assert.New(t)
must := func(v any, err error) any {
if err != nil {
Expand All @@ -30,12 +30,12 @@ func AssertGraphEqual(t *testing.T, expect, actual construct2.Graph, message str
assert.Equal(must(expect.Size()), must(actual.Size()), msg("size (# of edges) mismatch")...)

// Use the string representation to compare the graphs so that the diffs are nicer
eStr := must(construct2.String(expect))
aStr := must(construct2.String(actual))
eStr := must(construct.String(expect))
aStr := must(construct.String(actual))
assert.Equal(eStr, aStr, msg("graph mismatch")...)
}

func AssertGraphContains(t *testing.T, expect, actual construct2.Graph) {
func AssertGraphContains(t *testing.T, expect, actual construct.Graph) {
assert := assert.New(t)
must := func(v any, err error) any {
if err != nil {
Expand All @@ -44,27 +44,27 @@ func AssertGraphContains(t *testing.T, expect, actual construct2.Graph) {
return v
}

expectVs := must(construct2.TopologicalSort(expect)).([]construct2.ResourceId)
expectVs := must(construct.TopologicalSort(expect)).([]construct.ResourceId)
for _, expectV := range expectVs {
_, err := actual.Vertex(expectV)
assert.NoError(err)
}

expectEs := must(expect.Edges()).([]construct2.Edge)
expectEs := must(expect.Edges()).([]construct.Edge)
for _, expectE := range expectEs {
_, err := actual.Edge(expectE.Source, expectE.Target)
assert.NoError(err)
}
}

func StringToGraphElement(e string) (any, error) {
var id construct2.ResourceId
var id construct.ResourceId
idErr := id.Parse(e)
if id.Validate() == nil {
return id, nil
}

var path construct2.Path
var path construct.Path
pathErr := path.Parse(e)
if len(path) > 0 {
return path, nil
Expand All @@ -75,7 +75,7 @@ func StringToGraphElement(e string) (any, error) {

// AddElement is a utility function for adding an element to a graph. See [MakeGraph] for more information on supported
// element types. Returns whether adding the element failed.
func AddElement(t *testing.T, g construct2.Graph, e any) (failed bool) {
func AddElement(t *testing.T, g construct.Graph, e any) (failed bool) {
must := func(err error) {
if err != nil {
t.Fatal(err)
Expand All @@ -90,7 +90,7 @@ func AddElement(t *testing.T, g construct2.Graph, e any) (failed bool) {
}
}

addIfMissing := func(res *construct2.Resource) {
addIfMissing := func(res *construct.Resource) {
if _, err := g.Vertex(res.ID); errors.Is(err, graph.ErrVertexNotFound) {
must(g.AddVertex(res))
} else if err != nil {
Expand All @@ -99,33 +99,33 @@ func AddElement(t *testing.T, g construct2.Graph, e any) (failed bool) {
}

switch e := e.(type) {
case construct2.ResourceId:
addIfMissing(&construct2.Resource{ID: e})
case construct.ResourceId:
addIfMissing(&construct.Resource{ID: e})

case construct2.Resource:
case construct.Resource:
must(g.AddVertex(&e))

case *construct2.Resource:
case *construct.Resource:
must(g.AddVertex(e))

case construct2.Edge:
addIfMissing(&construct2.Resource{ID: e.Source})
addIfMissing(&construct2.Resource{ID: e.Target})
case construct.Edge:
addIfMissing(&construct.Resource{ID: e.Source})
addIfMissing(&construct.Resource{ID: e.Target})
must(g.AddEdge(e.Source, e.Target))

case construct2.ResourceEdge:
case construct.ResourceEdge:
addIfMissing(e.Source)
addIfMissing(e.Target)
must(g.AddEdge(e.Source.ID, e.Target.ID))

case construct2.SimpleEdge:
addIfMissing(&construct2.Resource{ID: e.Source})
addIfMissing(&construct2.Resource{ID: e.Target})
case construct.SimpleEdge:
addIfMissing(&construct.Resource{ID: e.Source})
addIfMissing(&construct.Resource{ID: e.Target})
must(g.AddEdge(e.Source, e.Target))

case construct2.Path:
case construct.Path:
for i, id := range e {
addIfMissing(&construct2.Resource{ID: id})
addIfMissing(&construct.Resource{ID: id})
if i > 0 {
must(g.AddEdge(e[i-1], id))
}
Expand All @@ -150,7 +150,7 @@ func AddElement(t *testing.T, g construct2.Graph, e any) (failed bool) {
// makeGraph := func(elements ...any) Graph {
// return MakeGraph(t, NewGraph(), elements...)
// }
func MakeGraph(t *testing.T, g construct2.Graph, elements ...any) construct2.Graph {
func MakeGraph(t *testing.T, g construct.Graph, elements ...any) construct.Graph {
failed := false
for i, e := range elements {
elemFailed := AddElement(t, g, e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/dominikbraun/graph"
construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"strings"
"testing"

"github.com/klothoplatform/klotho/pkg/construct2"
"github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)

func TestGraphToYAML(t *testing.T) {
makeGraph := func(elements ...any) construct2.Graph {
return MakeGraph(t, construct2.NewGraph(), elements...)
makeGraph := func(elements ...any) construct.Graph {
return MakeGraph(t, construct.NewGraph(), elements...)
}
tests := []struct {
name string
g construct2.Graph
g construct.Graph
yml string
}{
{
name: "empty graph",
g: construct2.NewGraph(),
g: construct.NewGraph(),
yml: `resources:
edges:`,
},
Expand Down Expand Up @@ -93,7 +93,7 @@ edges:
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)

b, err := yaml.Marshal(construct2.YamlGraph{Graph: tt.g})
b, err := yaml.Marshal(construct.YamlGraph{Graph: tt.g})
if !assert.NoError(err) {
return
}
Expand All @@ -104,7 +104,7 @@ edges:
"YAML diff",
)

got := construct2.YamlGraph{Graph: construct2.NewGraph()}
got := construct.YamlGraph{Graph: construct.NewGraph()}
err = yaml.Unmarshal(b, &got)
if !assert.NoError(err) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphtest
import (
"testing"

construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphtest
import (
"testing"

construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphtest
import (
"testing"

construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
)

func ParseId(t *testing.T, str string) (id construct.ResourceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphtest
import (
"testing"

construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/id_sort.go → pkg/construct/id_sort.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

// SortedIds is a helper type for sorting ResourceIds by purely their content, for use when deterministic ordering
// is desired (when no other sources of ordering are available).
Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/paths.go → pkg/construct/paths.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"strings"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/construct2/resource.go → pkg/construct/resource.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

type Resource struct {
ID ResourceId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package construct2
package construct

import (
"testing"
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions pkg/engine2/api.go → pkg/engine/api.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package engine2
package engine

import (
"github.com/klothoplatform/klotho/pkg/collectionutil"
construct "github.com/klothoplatform/klotho/pkg/construct2"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledge_base2"
construct "github.com/klothoplatform/klotho/pkg/construct"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledgebase"
)

func (e *Engine) ListResources() []construct.ResourceId {
Expand Down
14 changes: 7 additions & 7 deletions pkg/engine2/cli.go → pkg/engine/cli.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package engine2
package engine

import (
"bytes"
Expand All @@ -14,13 +14,13 @@ import (

"github.com/iancoleman/strcase"
"github.com/klothoplatform/klotho/pkg/closenicely"
construct "github.com/klothoplatform/klotho/pkg/construct2"
"github.com/klothoplatform/klotho/pkg/engine2/constraints"
engine_errs "github.com/klothoplatform/klotho/pkg/engine2/errors"
"github.com/klothoplatform/klotho/pkg/engine2/solution_context"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/klothoplatform/klotho/pkg/engine/constraints"
engine_errs "github.com/klothoplatform/klotho/pkg/engine/errors"
"github.com/klothoplatform/klotho/pkg/engine/solution_context"
kio "github.com/klothoplatform/klotho/pkg/io"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledge_base2"
"github.com/klothoplatform/klotho/pkg/knowledge_base2/reader"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledgebase"
"github.com/klothoplatform/klotho/pkg/knowledgebase/reader"
"github.com/klothoplatform/klotho/pkg/templates"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down
12 changes: 6 additions & 6 deletions pkg/engine2/constraints.go → pkg/engine/constraints.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package engine2
package engine

import (
"errors"
"fmt"

construct "github.com/klothoplatform/klotho/pkg/construct2"
"github.com/klothoplatform/klotho/pkg/engine2/constraints"
"github.com/klothoplatform/klotho/pkg/engine2/reconciler"
"github.com/klothoplatform/klotho/pkg/engine2/solution_context"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledge_base2"
construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/klothoplatform/klotho/pkg/engine/constraints"
"github.com/klothoplatform/klotho/pkg/engine/reconciler"
"github.com/klothoplatform/klotho/pkg/engine/solution_context"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledgebase"
)

func ApplyConstraints(ctx solution_context.SolutionContext) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

construct "github.com/klothoplatform/klotho/pkg/construct2"
construct "github.com/klothoplatform/klotho/pkg/construct"
)

type (
Expand Down
Loading
Loading