зеркало из https://github.com/Azure/orkestra.git
[WIP] Add tests for graph.go (#334)
This commit is contained in:
Родитель
49631d9867
Коммит
f33137a05c
|
@ -0,0 +1,10 @@
|
|||
package workflow
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoNodesFound = errors.New("no nodes found in the graph")
|
||||
ErrEntryNodeNotFound = errors.New("\"entry\" node not found")
|
||||
)
|
|
@ -3,7 +3,6 @@ package workflow
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
v1alpha13 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
|
||||
fluxhelmv2beta1 "github.com/fluxcd/helm-controller/api/v2beta1"
|
||||
|
@ -22,8 +21,8 @@ type Node struct {
|
|||
}
|
||||
|
||||
func Build(entry string, nodes map[string]v1alpha13.NodeStatus) (*Graph, error) {
|
||||
if nodes == nil || len(nodes) == 0 {
|
||||
return nil, fmt.Errorf("no nodes found in the graph")
|
||||
if len(nodes) == 0 {
|
||||
return nil, ErrNoNodesFound
|
||||
}
|
||||
|
||||
g := &Graph{
|
||||
|
@ -33,7 +32,7 @@ func Build(entry string, nodes map[string]v1alpha13.NodeStatus) (*Graph, error)
|
|||
|
||||
e, ok := nodes[entry]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("\"entry\" node not found")
|
||||
return nil, ErrEntryNodeNotFound
|
||||
}
|
||||
|
||||
err := g.bft(e)
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package workflow
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
v1alpha13 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
|
||||
)
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
type args struct {
|
||||
entry string
|
||||
nodes map[string]v1alpha13.NodeStatus
|
||||
}
|
||||
testmap := make(map[string]v1alpha13.NodeStatus)
|
||||
testmap["dummy"] = v1alpha13.NodeStatus{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *Graph
|
||||
err error
|
||||
}{
|
||||
//
|
||||
// TODO: Add more test cases.
|
||||
//
|
||||
{
|
||||
name: "testing nil nodes",
|
||||
args: args{
|
||||
entry: "",
|
||||
nodes: nil,
|
||||
},
|
||||
want: nil,
|
||||
err: ErrNoNodesFound,
|
||||
},
|
||||
{
|
||||
name: "testing unknown entry",
|
||||
args: args{
|
||||
entry: "unknown",
|
||||
nodes: testmap,
|
||||
},
|
||||
want: nil,
|
||||
err: ErrEntryNodeNotFound,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Build(tt.args.entry, tt.args.nodes)
|
||||
if err != tt.err {
|
||||
t.Errorf("Build() error = %v, want %v", err, tt.err)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("Build() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче