...
1 package testing
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
9 "github.com/devfile/library/v2/pkg/devfile/parser/data"
10 devfileFileSystem "github.com/devfile/library/v2/pkg/testingutil/filesystem"
11 "github.com/redhat-developer/odo/pkg/devfile/consts"
12 )
13
14 type InlinedComponent struct {
15 Name string
16 Inlined string
17 }
18
19 type URIComponent struct {
20 Name string
21 URI string
22 }
23
24
25 func SetupTestFolder(testFolderName string, fs devfileFileSystem.Filesystem) (devfileFileSystem.File, error) {
26 err := fs.MkdirAll(testFolderName, os.ModePerm)
27 if err != nil {
28 return nil, err
29 }
30 err = fs.MkdirAll(filepath.Join(testFolderName, consts.UriFolder), os.ModePerm)
31 if err != nil {
32 return nil, err
33 }
34 testFileName, err := fs.Create(filepath.Join(testFolderName, consts.UriFolder, "example.yaml"))
35 if err != nil {
36 return nil, err
37 }
38 return testFileName, nil
39 }
40
41
42 func GetDevfileData(t *testing.T, inlined []InlinedComponent, uriComp []URIComponent) data.DevfileData {
43 devfileData, err := data.NewDevfileData(string(data.APISchemaVersion200))
44 if err != nil {
45 t.Error(err)
46 }
47 for _, component := range inlined {
48 err = devfileData.AddComponents([]devfilev1.Component{{
49 Name: component.Name,
50 ComponentUnion: devfilev1.ComponentUnion{
51 Kubernetes: &devfilev1.KubernetesComponent{
52 K8sLikeComponent: devfilev1.K8sLikeComponent{
53 BaseComponent: devfilev1.BaseComponent{},
54 K8sLikeComponentLocation: devfilev1.K8sLikeComponentLocation{
55 Inlined: component.Inlined,
56 },
57 },
58 },
59 },
60 },
61 })
62 if err != nil {
63 t.Error(err)
64 }
65 }
66 for _, component := range uriComp {
67 err = devfileData.AddComponents([]devfilev1.Component{{
68 Name: component.Name,
69 ComponentUnion: devfilev1.ComponentUnion{
70 Kubernetes: &devfilev1.KubernetesComponent{
71 K8sLikeComponent: devfilev1.K8sLikeComponent{
72 BaseComponent: devfilev1.BaseComponent{},
73 K8sLikeComponentLocation: devfilev1.K8sLikeComponentLocation{
74 Uri: component.URI,
75 },
76 },
77 },
78 },
79 },
80 })
81 if err != nil {
82 t.Error(err)
83 }
84 }
85 return devfileData
86 }
87
View as plain text