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
168
169
170
171
172
173
174
175
176
|
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repository
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_getLicense(t *testing.T) {
type args struct {
name string
values *LicenseValues
}
tests := []struct {
name string
args args
want string
wantErr assert.ErrorAssertionFunc
}{
{
name: "regular",
args: args{
name: "MIT",
values: &LicenseValues{Owner: "Gitea", Year: "2023"},
},
want: `MIT License
Copyright (c) 2023 Gitea
Permission is hereby granted`,
wantErr: assert.NoError,
},
{
name: "license not found",
args: args{
name: "notfound",
},
wantErr: assert.Error,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetLicense(tt.args.name, tt.args.values)
if !tt.wantErr(t, err, fmt.Sprintf("GetLicense(%v, %v)", tt.args.name, tt.args.values)) {
return
}
assert.Contains(t, string(got), tt.want, "GetLicense(%v, %v)", tt.args.name, tt.args.values)
})
}
}
func Test_fillLicensePlaceholder(t *testing.T) {
type args struct {
name string
values *LicenseValues
origin string
}
tests := []struct {
name string
args args
want string
}{
{
name: "owner",
args: args{
name: "regular",
values: &LicenseValues{Year: "2023", Owner: "Gitea", Email: "teabot@gitea.io", Repo: "gitea"},
origin: `
<name of author>
<owner>
[NAME]
[name of copyright owner]
[name of copyright holder]
<COPYRIGHT HOLDERS>
<copyright holders>
<AUTHOR>
<author's name or designee>
[one or more legally recognised persons or entities offering the Work under the terms and conditions of this Licence]
`,
},
want: `
Gitea
Gitea
Gitea
Gitea
Gitea
Gitea
Gitea
Gitea
Gitea
Gitea
`,
},
{
name: "email",
args: args{
name: "regular",
values: &LicenseValues{Year: "2023", Owner: "Gitea", Email: "teabot@gitea.io", Repo: "gitea"},
origin: `
[EMAIL]
`,
},
want: `
teabot@gitea.io
`,
},
{
name: "repo",
args: args{
name: "regular",
values: &LicenseValues{Year: "2023", Owner: "Gitea", Email: "teabot@gitea.io", Repo: "gitea"},
origin: `
<program>
<one line to give the program's name and a brief idea of what it does.>
`,
},
want: `
gitea
gitea
`,
},
{
name: "year",
args: args{
name: "regular",
values: &LicenseValues{Year: "2023", Owner: "Gitea", Email: "teabot@gitea.io", Repo: "gitea"},
origin: `
<year>
[YEAR]
{YEAR}
[yyyy]
[Year]
[year]
`,
},
want: `
2023
2023
2023
2023
2023
2023
`,
},
{
name: "0BSD",
args: args{
name: "0BSD",
values: &LicenseValues{Year: "2023", Owner: "Gitea", Email: "teabot@gitea.io", Repo: "gitea"},
origin: `
Copyright (C) YEAR by AUTHOR EMAIL
...
... THE AUTHOR BE LIABLE FOR ...
`,
},
want: `
Copyright (C) 2023 by Gitea teabot@gitea.io
...
... THE AUTHOR BE LIABLE FOR ...
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, string(fillLicensePlaceholder(tt.args.name, tt.args.values, []byte(tt.args.origin))), "fillLicensePlaceholder(%v, %v, %v)", tt.args.name, tt.args.values, tt.args.origin)
})
}
}
|