-
Notifications
You must be signed in to change notification settings - Fork 26
/
example_test.go
100 lines (86 loc) · 1.84 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package draft_test
import (
"fmt"
"regexp"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/draft"
)
func ExamplePlanner_Resolve() {
buildpackPlanEntries := []packit.BuildpackPlanEntry{
{
Name: "fred",
},
{
Name: "clint",
Metadata: map[string]interface{}{
"version-source": "high",
},
},
{
Name: "fred",
Metadata: map[string]interface{}{
"version-source": "high",
},
},
{
Name: "fred",
Metadata: map[string]interface{}{
"version-source": "some-low-priority",
},
},
}
priorities := []interface{}{"high", regexp.MustCompile(`.*low.*`)}
planner := draft.NewPlanner()
entry, entries := planner.Resolve("fred", buildpackPlanEntries, priorities)
printEntry := func(e packit.BuildpackPlanEntry) {
var source string
source, ok := e.Metadata["version-source"].(string)
if !ok {
source = ""
}
fmt.Printf("%s => %q\n", e.Name, source)
}
fmt.Println("Highest Priority Entry")
printEntry(entry)
fmt.Println("Buildpack Plan Entry List Priority Sorted")
for _, e := range entries {
printEntry(e)
}
// Output:
// Highest Priority Entry
// fred => "high"
// Buildpack Plan Entry List Priority Sorted
// fred => "high"
// fred => "some-low-priority"
// fred => ""
}
func ExamplePlanner_MergeLayerTypes() {
buildpackPlanEntries := []packit.BuildpackPlanEntry{
{
Name: "fred",
},
{
Name: "clint",
Metadata: map[string]interface{}{
"build": false,
},
},
{
Name: "fred",
Metadata: map[string]interface{}{
"build": true,
},
},
{
Name: "fred",
Metadata: map[string]interface{}{
"launch": true,
},
},
}
planner := draft.NewPlanner()
launch, build := planner.MergeLayerTypes("fred", buildpackPlanEntries)
fmt.Printf("launch => %t; build => %t", launch, build)
// Output:
// launch => true; build => true
}