MCPcopy Create free account
hub / github.com/devfile/api / TestValidateEvents

Function TestValidateEvents

pkg/validation/events_test.go:28–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestValidateEvents(t *testing.T) {
29
30 containers := []string{"container1", "container2"}
31
32 commands := []v1alpha2.Command{
33 generateDummyApplyCommand("apply1", containers[0], nil, attributes.Attributes{}),
34 generateDummyApplyCommand("apply2", containers[0], nil, attributes.Attributes{}),
35 generateDummyExecCommand("exec1", containers[1], nil),
36 generateDummyExecCommand("exec2", containers[1], nil),
37 generateDummyCompositeCommand("compositeOnlyApply", []string{"apply1", "apply2"}, nil),
38 generateDummyCompositeCommand("compositeOnlyExec", []string{"exec1", "exec2"}, nil),
39 generateDummyCompositeCommand("compositeExecApply", []string{"exec1", "apply1"}, nil),
40 }
41
42 preStartPostStopErr := ".*does not map to a valid devfile command.*\n.*should either map to an apply command or a composite command with apply commands.*"
43 postStartPreStopErr := ".*does not map to a valid devfile command.*\n.*should either map to an exec command or a composite command with exec commands.*"
44
45 tests := []struct {
46 name string
47 events v1alpha2.Events
48 wantErr []string
49 }{
50 {
51 name: "Valid preStart events - Apply and Composite Apply Commands",
52 events: v1alpha2.Events{
53 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
54 PreStart: []string{
55 "apply1",
56 "apply2",
57 "compositeOnlyApply",
58 },
59 },
60 },
61 },
62 {
63 name: "Invalid exec commands in preStart",
64 events: v1alpha2.Events{
65 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
66 PreStart: []string{
67 "apply12",
68 "exec2",
69 "compositeExecApply",
70 },
71 },
72 },
73 wantErr: []string{preStartPostStopErr},
74 },
75 {
76 name: "Invalid exec commands in postStop",
77 events: v1alpha2.Events{
78 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
79 PostStop: []string{
80 "apply12",
81 "exec2",
82 "compositeExecApply",
83 },
84 },
85 },

Callers

nothing calls this directly

Calls 5

generateDummyExecCommandFunction · 0.85
ValidateEventsFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected