Skip to content

Commit e7282a4

Browse files
SubDir non-existent destination bug fixed (#124)
* check for if cloned starter project exists before archiving added. * Test cases for git cloning rewritten. 'Maven Java (without subdir)' renamed to 'Maven Java'. 'Maven Java (with subdir)' rewritten to test 'Wildfly Java - microprofile-config subdirectory'. * spelling mistakes corrected. * 'Maven Java (with subdir)' test case restored as additional case. * bug fixed. gitSubDir now creates destinationPath if non-existent. * parameter names added. Signed-off-by: Michael Valdron <[email protected]>
1 parent a7d0871 commit e7282a4

File tree

2 files changed

+104
-62
lines changed

2 files changed

+104
-62
lines changed

index/generator/library/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func DownloadStackFromGit(git *schema.Git, path string, verbose bool) ([]byte, e
111111
return []byte{}, err
112112
}
113113

114+
// Throw error if path was not created
115+
if _, err := os.Stat(path); os.IsNotExist(err) {
116+
return []byte{}, err
117+
}
118+
114119
// Zip directory containing downloaded git repo
115120
if err := ZipDir(path, zipPath); err != nil {
116121
return []byte{}, err
@@ -208,6 +213,19 @@ func gitSubDir(srcPath, destinationPath, subDir string, fs filesystem.Filesystem
208213
return err
209214
}
210215

216+
// Create destinationPath if does not exist
217+
if _, err = fs.Stat(destinationPath); os.IsNotExist(err) {
218+
var srcinfo os.FileInfo
219+
220+
if srcinfo, err = fs.Stat(srcPath); err != nil {
221+
return err
222+
}
223+
224+
if err = fs.MkdirAll(destinationPath, srcinfo.Mode()); err != nil {
225+
return err
226+
}
227+
}
228+
211229
// Loop over files.
212230
for outputIndex := range outputDirFiles {
213231
outputFileHere := outputDirFiles[outputIndex]

index/generator/library/util_test.go

Lines changed: 86 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,69 @@ func TestCloneRemoteStack(t *testing.T) {
2424
wantErrStr string
2525
}{
2626
{
27-
"Case 1: Maven Java (Without subDir)",
28-
&schema.Git{
27+
name: "Case 1: Maven Java",
28+
git: &schema.Git{
2929
Url: "https://github.com/odo-devfiles/springboot-ex.git",
3030
RemoteName: "origin",
3131
},
32-
filepath.Join(os.TempDir(), "springboot-ex"),
33-
false,
34-
"",
32+
path: filepath.Join(os.TempDir(), "springboot-ex"),
33+
wantErr: false,
34+
wantErrStr: "",
3535
},
3636
{
37-
"Case 2: Maven Java (With subDir)",
38-
&schema.Git{
37+
name: "Case 2: Maven Java (With subDir)",
38+
git: &schema.Git{
3939
Url: "https://github.com/odo-devfiles/springboot-ex.git",
4040
RemoteName: "origin",
4141
SubDir: "src/main",
4242
},
43-
filepath.Join(os.TempDir(), "springboot-ex"),
44-
false,
45-
"",
43+
path: filepath.Join(os.TempDir(), "springboot-ex"),
44+
wantErr: false,
45+
wantErrStr: "",
4646
},
4747
{
48-
"Case 3: Maven Java - Cloning with Hash Revision",
49-
&schema.Git{
48+
name: "Case 3: Wildfly Java - microprofile-config subdirectory",
49+
git: &schema.Git{
50+
Url: "https://github.com/wildfly/quickstart.git",
51+
RemoteName: "wildfly-quickstart",
52+
Revision: "22.0.1.Final",
53+
SubDir: "microprofile-config",
54+
},
55+
path: filepath.Join(os.TempDir(), "quickstart"),
56+
wantErr: false,
57+
wantErrStr: "",
58+
},
59+
{
60+
name: "Case 4: Maven Java - Cloning with Hash Revision",
61+
git: &schema.Git{
5062
Url: "https://github.com/odo-devfiles/springboot-ex.git",
5163
RemoteName: "origin",
5264
Revision: "694e96286ffdc3a9990d0041637d32cecba38181",
5365
},
54-
filepath.Join(os.TempDir(), "springboot-ex"),
55-
true,
56-
"specifying commit in 'revision' is not yet supported",
66+
path: filepath.Join(os.TempDir(), "springboot-ex"),
67+
wantErr: true,
68+
wantErrStr: "specifying commit in 'revision' is not yet supported",
5769
},
5870
{
59-
"Case 4: Cloning a non-existant repo",
60-
&schema.Git{
71+
name: "Case 5: Cloning a non-existent repo",
72+
git: &schema.Git{
6173
Url: "https://github.com/odo-devfiles/nonexist.git",
6274
RemoteName: "origin",
6375
},
64-
filepath.Join(os.TempDir(), "nonexist"),
65-
true,
66-
"",
76+
path: filepath.Join(os.TempDir(), "nonexist"),
77+
wantErr: true,
78+
wantErrStr: "",
6779
},
6880
{
69-
"Case 5: Maven Java - Cloning with Invalid Revision",
70-
&schema.Git{
81+
name: "Case 6: Maven Java - Cloning with Invalid Revision",
82+
git: &schema.Git{
7183
Url: "https://github.com/odo-devfiles/springboot-ex.git",
7284
RemoteName: "origin",
7385
Revision: "invalid",
7486
},
75-
filepath.Join(os.TempDir(), "springboot-ex"),
76-
true,
77-
"couldn't find remote ref \"refs/tags/invalid\"",
87+
path: filepath.Join(os.TempDir(), "springboot-ex"),
88+
wantErr: true,
89+
wantErrStr: "couldn't find remote ref \"refs/tags/invalid\"",
7890
},
7991
}
8092

@@ -110,34 +122,34 @@ func TestDownloadStackFromZipUrl(t *testing.T) {
110122
wantErrStr string
111123
}{
112124
{
113-
"Case 1: Java Quarkus (Without subDir)",
114-
map[string]string{
125+
name: "Case 1: Java Quarkus",
126+
params: map[string]string{
115127
"Name": "quarkus",
116128
"ZipUrl": "https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile",
117129
"SubDir": "",
118130
},
119-
false,
120-
"",
131+
wantErr: false,
132+
wantErrStr: "",
121133
},
122134
{
123-
"Case 2: Java Quarkus (With subDir)",
124-
map[string]string{
135+
name: "Case 2: Java Quarkus (With subDir)",
136+
params: map[string]string{
125137
"Name": "quarkus",
126138
"ZipUrl": "https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile",
127139
"SubDir": "src",
128140
},
129-
false,
130-
"",
141+
wantErr: false,
142+
wantErrStr: "",
131143
},
132144
{
133-
"Case 3: Download error",
134-
map[string]string{
145+
name: "Case 3: Download error",
146+
params: map[string]string{
135147
"Name": "quarkus",
136148
"ZipUrl": "https://code.quarkus.io/d?e=io.quarkus",
137149
"SubDir": "",
138150
},
139-
true,
140-
"failed to retrieve https://code.quarkus.io/d?e=io.quarkus, 400: Bad Request",
151+
wantErr: true,
152+
wantErrStr: "failed to retrieve https://code.quarkus.io/d?e=io.quarkus, 400: Bad Request",
141153
},
142154
}
143155

@@ -179,57 +191,69 @@ func TestDownloadStackFromGit(t *testing.T) {
179191
wantErrStr string
180192
}{
181193
{
182-
"Case 1: Maven Java (Without subDir)",
183-
&schema.Git{
194+
name: "Case 1: Maven Java",
195+
git: &schema.Git{
184196
Url: "https://github.com/odo-devfiles/springboot-ex.git",
185197
RemoteName: "origin",
186198
},
187-
filepath.Join(os.TempDir(), "springboot-ex"),
188-
false,
189-
"",
199+
path: filepath.Join(os.TempDir(), "springboot-ex"),
200+
wantErr: false,
201+
wantErrStr: "",
190202
},
191203
{
192-
"Case 2: Maven Java (With subDir)",
193-
&schema.Git{
204+
name: "Case 2: Maven Java (With subDir)",
205+
git: &schema.Git{
194206
Url: "https://github.com/odo-devfiles/springboot-ex.git",
195207
RemoteName: "origin",
196208
SubDir: "src/main",
197209
},
198-
filepath.Join(os.TempDir(), "springboot-ex-main"),
199-
false,
200-
"",
210+
path: filepath.Join(os.TempDir(), "springboot-ex"),
211+
wantErr: false,
212+
wantErrStr: "",
213+
},
214+
{
215+
name: "Case 3: Wildfly Java - microprofile-config subdirectory",
216+
git: &schema.Git{
217+
Url: "https://github.com/wildfly/quickstart.git",
218+
RemoteName: "wildfly-quickstart",
219+
Revision: "22.0.1.Final",
220+
SubDir: "microprofile-config",
221+
},
222+
path: filepath.Join(os.TempDir(), "quickstart"),
223+
wantErr: false,
224+
wantErrStr: "",
201225
},
202226
{
203-
"Case 3: Maven Java - Cloning with Hash Revision",
204-
&schema.Git{
227+
name: "Case 4: Maven Java - Cloning with Hash Revision",
228+
git: &schema.Git{
205229
Url: "https://github.com/odo-devfiles/springboot-ex.git",
206230
RemoteName: "origin",
207231
Revision: "694e96286ffdc3a9990d0041637d32cecba38181",
208232
},
209-
filepath.Join(os.TempDir(), "springboot-ex"),
210-
true,
211-
"specifying commit in 'revision' is not yet supported",
233+
path: filepath.Join(os.TempDir(), "springboot-ex"),
234+
wantErr: true,
235+
wantErrStr: "specifying commit in 'revision' is not yet supported",
212236
},
213237
{
214-
"Case 4: Cloning a non-existant repo",
215-
&schema.Git{
238+
name: "Case 5: Cloning a non-existent repo",
239+
git: &schema.Git{
216240
Url: "https://github.com/odo-devfiles/nonexist.git",
217241
RemoteName: "origin",
218242
},
219-
filepath.Join(os.TempDir(), "nonexist"),
220-
true,
221-
"",
243+
path: filepath.Join(os.TempDir(), "nonexist"),
244+
wantErr: true,
245+
wantErrStr: "",
222246
},
223247
{
224-
"Case 5: Maven Java - Cloning with Invalid Revision",
225-
&schema.Git{
248+
name: "Case 6: Maven Java - Cloning with Invalid Revision",
249+
git: &schema.Git{
226250
Url: "https://github.com/odo-devfiles/springboot-ex.git",
227251
RemoteName: "origin",
228252
Revision: "invalid",
229253
},
230-
filepath.Join(os.TempDir(), "springboot-ex"),
231-
true,
232-
"couldn't find remote ref \"refs/tags/invalid\"",
254+
path: filepath.Join(os.TempDir(), "springboot-ex"),
255+
wantErr: true,
256+
wantErrStr: "couldn't find remote ref \"refs/tags/invalid\"",
233257
},
234258
}
235259

0 commit comments

Comments
 (0)