1 package devstate
2
3 import (
4 "testing"
5
6 "github.com/google/go-cmp/cmp"
7 . "github.com/redhat-developer/odo/pkg/apiserver-gen/go"
8 )
9
10 func TestDevfileState_SetMetadata(t *testing.T) {
11 type args struct {
12 name string
13 version string
14 displayName string
15 description string
16 tags string
17 architectures string
18 icon string
19 globalMemoryLimit string
20 projectType string
21 language string
22 website string
23 provider string
24 supportUrl string
25 }
26 tests := []struct {
27 name string
28 state func() DevfileState
29 args args
30 want DevfileContent
31 wantErr bool
32 }{
33 {
34 name: "Set metadata",
35 state: func() DevfileState {
36 return NewDevfileState()
37 },
38 args: args{
39 name: "a-name",
40 version: "v1.1.1",
41 displayName: "a display name",
42 description: "a description",
43 tags: "tag1,tag2",
44 architectures: "arch1,arch2",
45 icon: "an.ico",
46 globalMemoryLimit: "1Gi",
47 projectType: "a project type",
48 language: "a language",
49 website: "http://example.com",
50 provider: "a provider",
51 supportUrl: "http://support.example.com",
52 },
53 want: DevfileContent{
54 Content: `metadata:
55 architectures:
56 - arch1
57 - arch2
58 description: a description
59 displayName: a display name
60 globalMemoryLimit: 1Gi
61 icon: an.ico
62 language: a language
63 name: a-name
64 projectType: a project type
65 provider: a provider
66 supportUrl: http://support.example.com
67 tags:
68 - tag1
69 - tag2
70 version: v1.1.1
71 website: http://example.com
72 schemaVersion: 2.2.0
73 `,
74 Version: "2.2.0",
75 Commands: []Command{},
76 Containers: []Container{},
77 Images: []Image{},
78 Resources: []Resource{},
79 Volumes: []Volume{},
80 Metadata: Metadata{
81 Name: "a-name",
82 Version: "v1.1.1",
83 DisplayName: "a display name",
84 Description: "a description",
85 Tags: "tag1,tag2",
86 Architectures: "arch1,arch2",
87 Icon: "an.ico",
88 GlobalMemoryLimit: "1Gi",
89 ProjectType: "a project type",
90 Language: "a language",
91 Website: "http://example.com",
92 Provider: "a provider",
93 SupportUrl: "http://support.example.com",
94 },
95 },
96 },
97
98 }
99 for _, tt := range tests {
100 t.Run(tt.name, func(t *testing.T) {
101 o := tt.state()
102 got, err := o.SetMetadata(tt.args.name, tt.args.version, tt.args.displayName, tt.args.description, tt.args.tags, tt.args.architectures, tt.args.icon, tt.args.globalMemoryLimit, tt.args.projectType, tt.args.language, tt.args.website, tt.args.provider, tt.args.supportUrl)
103 if (err != nil) != tt.wantErr {
104 t.Errorf("DevfileState.SetMetadata() error = %v, wantErr %v", err, tt.wantErr)
105 return
106 }
107 if diff := cmp.Diff(tt.want, got); diff != "" {
108 t.Errorf("DevfileState.SetMetadata() mismatch (-want +got):\n%s", diff)
109 }
110 })
111 }
112 }
113
View as plain text