@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package proposal
17
+ package repo_test
18
18
19
19
import (
20
20
"bytes"
@@ -26,6 +26,7 @@ import (
26
26
"github.com/stretchr/testify/require"
27
27
28
28
"k8s.io/enhancements/api"
29
+ "k8s.io/enhancements/pkg/repo"
29
30
"sigs.k8s.io/yaml"
30
31
)
31
32
@@ -34,55 +35,83 @@ func TestWriteKep(t *testing.T) {
34
35
name string
35
36
kepFile string
36
37
repoPath string
37
- opts CreateOpts
38
+ kepName string
39
+ sig string
38
40
expectedPath string
39
41
expectError bool
40
42
}{
41
43
{
42
- name : "simple kep" ,
43
- kepFile : "testdata/valid-kep.yaml" ,
44
- repoPath : "enhancements" ,
45
- opts : CreateOpts {
46
- CommonArgs : CommonArgs {
47
- Name : "1010-test" ,
48
- SIG : "sig-auth" ,
49
- },
50
- },
44
+ name : "simple KEP" ,
45
+ kepFile : "testdata/valid-kep.yaml" ,
46
+ repoPath : "enhancements" ,
47
+ kepName : "1010-test" ,
48
+ sig : "sig-auth" ,
51
49
expectedPath : filepath .Join ("enhancements" , "keps" , "sig-auth" , "1010-test" ),
52
50
expectError : false ,
53
51
},
54
52
{
55
- name : "opts repo path works" ,
56
- kepFile : "testdata/valid-kep.yaml" ,
57
- repoPath : "" ,
58
- opts : CreateOpts {
59
- CommonArgs : CommonArgs {
60
- Name : "1011-test" ,
61
- SIG : "sig-architecture" ,
62
- RepoPath : "enhancementz" ,
63
- },
64
- },
65
- expectedPath : filepath .Join ("enhancementz" , "keps" , "sig-architecture" , "1011-test" ),
66
- expectError : false ,
53
+ name : "missing KEP name" ,
54
+ kepFile : "testdata/valid-kep.yaml" ,
55
+ repoPath : "enhancements" ,
56
+ sig : "sig-auth" ,
57
+ expectedPath : filepath .Join ("enhancements" , "keps" , "sig-auth" , "1010-test" ),
58
+ expectError : true ,
59
+ },
60
+ {
61
+ name : "missing owning SIG" ,
62
+ kepFile : "testdata/valid-kep.yaml" ,
63
+ repoPath : "enhancements" ,
64
+ kepName : "1010-test" ,
65
+ expectedPath : filepath .Join ("enhancements" , "keps" , "sig-auth" , "1010-test" ),
66
+ expectError : true ,
67
67
},
68
68
}
69
69
70
70
for _ , tc := range testcases {
71
71
t .Run (tc .name , func (t * testing.T ) {
72
72
tempDir , err := ioutil .TempDir ("" , "" )
73
+ mkErr := os .MkdirAll (
74
+ filepath .Join (
75
+ tempDir ,
76
+ tc .repoPath ,
77
+ repo .ProposalPathStub ,
78
+ repo .PRRApprovalPathStub ,
79
+ ),
80
+ os .ModePerm ,
81
+ )
82
+
83
+ require .Nil (t , mkErr )
84
+
85
+ templatePath := filepath .Join (
86
+ tempDir ,
87
+ tc .repoPath ,
88
+ repo .ProposalPathStub ,
89
+ repo .ProposalTemplatePathStub ,
90
+ )
91
+
92
+ mkErr = os .MkdirAll (
93
+ templatePath ,
94
+ os .ModePerm ,
95
+ )
96
+
97
+ require .Nil (t , mkErr )
98
+
99
+ templateFile := filepath .Join (templatePath , repo .ProposalFilename )
100
+ emptyTemplate , fileErr := os .Create (templateFile )
101
+ require .Nil (t , fileErr )
102
+ emptyTemplate .Close ()
103
+
73
104
defer func () {
74
105
t .Logf ("cleanup!" )
75
106
err := os .RemoveAll (tempDir )
76
107
if err != nil {
77
108
t .Logf ("error cleaning up test: %s" , err )
78
109
}
79
110
}()
111
+
80
112
require .NoError (t , err )
81
- repoPath := tc .repoPath
82
- if repoPath == "" {
83
- repoPath = tc .opts .RepoPath
84
- }
85
113
114
+ repoPath := tc .repoPath
86
115
repoPath = filepath .Join (tempDir , repoPath )
87
116
c := newTestClient (t , repoPath )
88
117
@@ -93,8 +122,17 @@ func TestWriteKep(t *testing.T) {
93
122
err = yaml .Unmarshal (b , & p )
94
123
require .NoError (t , err )
95
124
96
- tc .opts .CommonArgs .RepoPath = repoPath
97
- err = c .writeKEP (& p , & tc .opts .CommonArgs )
125
+ p .OwningSIG = tc .sig
126
+ p .Name = tc .kepName
127
+
128
+ err = c .r .WriteKEP (& p )
129
+
130
+ files , readErr := ioutil .ReadDir (c .r .ProposalPath )
131
+ require .Nil (t , readErr )
132
+
133
+ for _ , f := range files {
134
+ t .Logf (f .Name ())
135
+ }
98
136
99
137
if tc .expectError {
100
138
require .Error (t , err )
@@ -106,7 +144,7 @@ func TestWriteKep(t *testing.T) {
106
144
require .NoError (t , err )
107
145
require .NotNil (t , dirStat )
108
146
require .True (t , dirStat .IsDir ())
109
- p := filepath .Join (computedPath , "kep.yaml" )
147
+ p := filepath .Join (computedPath , repo . ProposalMetadataFilename )
110
148
fileStat , err := os .Stat (p )
111
149
require .NoError (t , err )
112
150
require .NotNil (t , fileStat )
@@ -118,38 +156,48 @@ func TestWriteKep(t *testing.T) {
118
156
type testClient struct {
119
157
T * testing.T
120
158
b * bytes.Buffer
121
- * Client
159
+ r * repo. Repo
122
160
}
123
161
124
162
func newTestClient (t * testing.T , repoPath string ) testClient {
125
163
b := & bytes.Buffer {}
126
164
tc := testClient {
127
165
T : t ,
128
166
b : b ,
129
- Client : & Client {
130
- RepoPath : repoPath ,
131
- Out : b ,
132
- },
133
167
}
134
168
169
+ r , err := repo .New (repoPath )
170
+ require .Nil (t , err )
171
+
172
+ r .Out = b
173
+ tc .r = r
174
+
135
175
// TODO: Parameterize
136
- tc .addTemplate ("kep.yaml" )
137
- tc .addTemplate ("README.md" )
176
+ tc .addTemplate (repo .ProposalMetadataFilename )
177
+ tc .addTemplate (repo .ProposalFilename )
178
+
138
179
return tc
139
180
}
140
181
141
182
func (tc * testClient ) addTemplate (file string ) {
142
- src := filepath .Join ("testdata" , "templates" , file )
183
+ src := filepath .Join (
184
+ "testdata" ,
185
+ repo .ProposalPathStub ,
186
+ repo .ProposalTemplatePathStub ,
187
+ file ,
188
+ )
189
+
143
190
data , err := ioutil .ReadFile (src )
144
191
if err != nil {
145
192
tc .T .Fatal (err )
146
193
}
147
194
148
- dirPath := filepath .Join (tc .Client . RepoPath , "keps" , "NNNN-kep-template" )
195
+ dirPath := filepath .Join (tc .r . BasePath , repo . ProposalPathStub , repo . ProposalTemplatePathStub )
149
196
err = os .MkdirAll (dirPath , os .ModePerm )
150
197
if err != nil {
151
198
tc .T .Fatal (err )
152
199
}
200
+
153
201
dest := filepath .Join (dirPath , file )
154
202
tc .T .Logf ("Writing %s to %s" , file , dest )
155
203
err = ioutil .WriteFile (dest , data , os .ModePerm )
0 commit comments