...
1 package validate
2
3 import (
4 "testing"
5
6 devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
7 "github.com/google/go-cmp/cmp"
8 )
9
10 func TestValidateComponents(t *testing.T) {
11
12 t.Run("No components present", func(t *testing.T) {
13
14
15 components := []devfilev1.Component{}
16
17 got := validateComponents(components)
18 want := &NoComponentsError{}
19
20 if diff := cmp.Diff(want, got); diff != "" {
21 t.Errorf("validateComponents() mismatch (-want +got):\n%s", diff)
22 }
23 })
24
25 t.Run("Container type component present", func(t *testing.T) {
26
27 components := []devfilev1.Component{
28 {
29 Name: "container",
30 ComponentUnion: devfilev1.ComponentUnion{
31 Container: &devfilev1.ContainerComponent{
32 Container: devfilev1.Container{
33 Image: "image",
34 },
35 },
36 },
37 },
38 }
39
40 got := validateComponents(components)
41
42 if got != nil {
43 t.Errorf("TestValidateComponents error - Not expecting an error: '%v'", got)
44 }
45 })
46 }
47
View as plain text