-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathv0v1methods_test.go
More file actions
167 lines (153 loc) · 5.65 KB
/
v0v1methods_test.go
File metadata and controls
167 lines (153 loc) · 5.65 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package publiccode
import (
"net/url"
"testing"
)
func TestPublicCodeV0Version(t *testing.T) {
p := PublicCodeV0{}
if p.Version() != 0 {
t.Errorf("expected 0, got %d", p.Version())
}
}
func TestPublicCodeV0UrlNil(t *testing.T) {
p := PublicCodeV0{URL: nil}
if p.Url() != nil {
t.Error("expected nil")
}
}
func TestPublicCodeV0UrlValid(t *testing.T) {
raw, _ := url.Parse("https://github.com/example/repo")
u := (*URL)(raw)
p := PublicCodeV0{URL: u}
if p.Url() == nil {
t.Error("expected non-nil URL")
}
}
func TestPublicCodeV0UrlInvalid(t *testing.T) {
// A URL with no host/scheme won't pass IsValidURL.
raw := &url.URL{Path: "/just/a/path"}
u := (*URL)(raw)
p := PublicCodeV0{URL: u}
if p.Url() != nil {
t.Error("expected nil for invalid URL")
}
}
func TestPublicCodeV0ToYAMLClearsIt(t *testing.T) {
raw, _ := url.Parse("https://github.com/example/repo.git")
u := (*URL)(raw)
releaseDate := "2024-01-01"
locReady := true
p := PublicCodeV0{
PubliccodeYamlVersion: "0",
Name: "test",
URL: u,
ReleaseDate: &releaseDate,
Platforms: []string{"web"},
DevelopmentStatus: "stable",
SoftwareType: "standalone/web",
Description: map[string]DescV0{
"en": {
ShortDescription: "short",
LongDescription: "long description that is at least 150 chars: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
GenericName: "Generic",
},
},
Legal: struct {
License string `json:"license" validate:"required,is_spdx_expression" yaml:"license"`
MainCopyrightOwner *string `json:"mainCopyrightOwner,omitempty" yaml:"mainCopyrightOwner,omitempty"`
RepoOwner *string `json:"repoOwner,omitempty" yaml:"repoOwner,omitempty"`
AuthorsFile *string `json:"authorsFile,omitempty" yaml:"authorsFile,omitempty"`
}{License: "MIT"},
Maintenance: struct {
Type string `json:"type" validate:"required,oneof=internal contract community none" yaml:"type"`
Contractors *[]ContractorV0 `json:"contractors,omitempty" validate:"required_if=Type contract,excluded_unless=Type contract,omitempty,dive" yaml:"contractors,omitempty"`
Contacts *[]ContactV0 `json:"contacts,omitempty" validate:"required_if=Type community,required_if=Type internal,omitempty,dive" yaml:"contacts,omitempty"`
}{Type: "none"},
Localisation: struct {
LocalisationReady *bool `json:"localisationReady" validate:"required" yaml:"localisationReady"`
AvailableLanguages []string `json:"availableLanguages" validate:"required,gt=0,dive,bcp47_strict_language_tag" yaml:"availableLanguages"`
}{
LocalisationReady: &locReady,
AvailableLanguages: []string{"en"},
},
}
it := &ITSectionV0{}
p.It = it
b, err := p.ToYAML()
if err != nil {
t.Fatalf("ToYAML failed: %v", err)
}
if len(b) == 0 {
t.Error("expected non-empty YAML output")
}
}
func TestPublicCodeV1Version(t *testing.T) {
p := PublicCodeV1{}
if p.Version() != 1 {
t.Errorf("expected 1, got %d", p.Version())
}
}
func TestPublicCodeV1UrlNil(t *testing.T) {
p := PublicCodeV1{URL: nil}
if p.Url() != nil {
t.Error("expected nil")
}
}
func TestPublicCodeV1UrlValid(t *testing.T) {
raw, _ := url.Parse("https://github.com/example/repo")
u := (*URL)(raw)
p := PublicCodeV1{URL: u}
if p.Url() == nil {
t.Error("expected non-nil URL")
}
}
func TestPublicCodeV1UrlInvalid(t *testing.T) {
raw := &url.URL{Path: "/just/a/path"}
u := (*URL)(raw)
p := PublicCodeV1{URL: u}
if p.Url() != nil {
t.Error("expected nil for invalid URL")
}
}
func TestPublicCodeV1ToYAML(t *testing.T) {
raw, _ := url.Parse("https://github.com/example/repo.git")
u := (*URL)(raw)
locReady := true
p := PublicCodeV1{
PubliccodeYamlVersion: "1",
Name: "test",
URL: u,
Platforms: []string{"web"},
DevelopmentStatus: "stable",
SoftwareType: "standalone/web",
Description: map[string]DescV1{
"en": {
ShortDescription: "short",
LongDescription: "long description that is at least 150 chars: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
},
},
Legal: struct {
License string `json:"license" validate:"required,is_spdx_expression" yaml:"license"`
MainCopyrightOwner *string `json:"mainCopyrightOwner,omitempty" yaml:"mainCopyrightOwner,omitempty"`
}{License: "MIT"},
Maintenance: struct {
Type string `json:"type" validate:"required,oneof=internal contract community none" yaml:"type"`
Contractors *[]ContractorV1 `json:"contractors,omitempty" validate:"required_if=Type contract,excluded_unless=Type contract,omitempty,dive" yaml:"contractors,omitempty"`
Contacts *[]ContactV1 `json:"contacts,omitempty" validate:"required_if=Type community,required_if=Type internal,omitempty,dive" yaml:"contacts,omitempty"`
}{Type: "none"},
Localisation: struct {
LocalisationReady *bool `json:"localisationReady" validate:"required" yaml:"localisationReady"`
AvailableLanguages []string `json:"availableLanguages" validate:"required,gt=0,dive,bcp47_strict_language_tag" yaml:"availableLanguages"`
}{
LocalisationReady: &locReady,
AvailableLanguages: []string{"en"},
},
}
b, err := p.ToYAML()
if err != nil {
t.Fatalf("ToYAML failed: %v", err)
}
if len(b) == 0 {
t.Error("expected non-empty YAML output")
}
}