github.com/erda-project/erda-infra@v1.0.9/base/servicehub/dependency-graph/dependency_graph_test.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package graph 16 17 import "fmt" 18 19 func Example_circular() { 20 node1 := NewNode("node1", "node2") 21 node2 := NewNode("node2", "node3") 22 node3 := NewNode("node3", "node1") 23 var g Graph 24 g = append(g, node1, node2, node3) 25 g, err := Resolve(g) 26 if err != nil { 27 fmt.Println(err) 28 // g.Display() 29 return 30 } 31 fmt.Println("OK") 32 // Output: 33 // Circular dependency found 34 } 35 36 func Example_ok() { 37 node1 := NewNode("node1", "node2") 38 node2 := NewNode("node2", "node3") 39 node3 := NewNode("node3") 40 var g Graph 41 g = append(g, node1, node2, node3) 42 g, err := Resolve(g) 43 if err != nil { 44 fmt.Println(err) 45 g.Display() 46 return 47 } 48 fmt.Println("OK") 49 g.Display() 50 // Output: 51 // OK 52 // node3 53 // node2 -> node3 54 // node1 -> node2 55 }