-
Notifications
You must be signed in to change notification settings - Fork 244
/
devfile.go
121 lines (111 loc) · 3.54 KB
/
devfile.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package testingutil
import (
versionsCommon "github.com/openshift/odo/pkg/devfile/parser/data/common"
)
// TestDevfileData is a convenience data type used to mock up a devfile configuration
type TestDevfileData struct {
ComponentType versionsCommon.DevfileComponentType
CommandActions []versionsCommon.DevfileCommandAction
MissingBuildCommand bool
}
// GetComponents is a mock function to get the components from a devfile
func (d TestDevfileData) GetComponents() []versionsCommon.DevfileComponent {
return d.GetAliasedComponents()
}
// GetAliasedComponents is a mock function to get the components that have an alias from a devfile
func (d TestDevfileData) GetAliasedComponents() []versionsCommon.DevfileComponent {
alias := [...]string{"alias1", "alias2"}
image := [...]string{"docker.io/maven:latest", "docker.io/hello-world:latest"}
memoryLimit := "128Mi"
volumeName := [...]string{"myvolume1", "myvolume2"}
volumePath := [...]string{"/my/volume/mount/path1", "/my/volume/mount/path2"}
return []versionsCommon.DevfileComponent{
{
Alias: &alias[0],
DevfileComponentDockerimage: versionsCommon.DevfileComponentDockerimage{
Image: &image[0],
Command: []string{},
Args: []string{},
Env: []versionsCommon.DockerimageEnv{},
MemoryLimit: &memoryLimit,
Volumes: []versionsCommon.DockerimageVolume{
{
Name: &volumeName[0],
ContainerPath: &volumePath[0],
},
},
},
Type: d.ComponentType,
},
{
Alias: &alias[1],
DevfileComponentDockerimage: versionsCommon.DevfileComponentDockerimage{
Image: &image[1],
Command: []string{},
Args: []string{},
Env: []versionsCommon.DockerimageEnv{},
MemoryLimit: &memoryLimit,
Volumes: []versionsCommon.DockerimageVolume{
{
Name: &volumeName[0],
ContainerPath: &volumePath[0],
},
{
Name: &volumeName[1],
ContainerPath: &volumePath[1],
},
},
},
Type: d.ComponentType,
},
}
}
// GetProjects is a mock function to get the components that have an alias from a devfile
func (d TestDevfileData) GetProjects() []versionsCommon.DevfileProject {
projectName := [...]string{"test-project", "anotherproject"}
clonePath := [...]string{"/test-project", "/anotherproject"}
sourceLocation := [...]string{"https://github.com/someproject/test-project.git", "https://github.com/another/project.git"}
return []versionsCommon.DevfileProject{
{
ClonePath: &clonePath[0],
Name: projectName[0],
Source: versionsCommon.DevfileProjectSource{
Type: versionsCommon.DevfileProjectTypeGit,
Location: sourceLocation[0],
},
},
{
ClonePath: &clonePath[1],
Name: projectName[1],
Source: versionsCommon.DevfileProjectSource{
Type: versionsCommon.DevfileProjectTypeGit,
Location: sourceLocation[1],
},
},
}
}
// GetCommands is a mock function to get the commands from a devfile
func (d TestDevfileData) GetCommands() []versionsCommon.DevfileCommand {
commandName := [...]string{"devbuild", "devrun", "customcommand"}
commands := []versionsCommon.DevfileCommand{
{
Name: commandName[1],
Actions: d.CommandActions,
},
{
Name: commandName[2],
Actions: d.CommandActions,
},
}
if !d.MissingBuildCommand {
commands = append(commands, versionsCommon.DevfileCommand{
Name: commandName[0],
Actions: d.CommandActions,
})
}
return commands
}
// Validate is a mock validation that always validates without error
func (d TestDevfileData) Validate() error {
return nil
}