Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubDir non-existent destination bug fix #124

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index/generator/library/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func DownloadStackFromGit(git *schema.Git, path string, verbose bool) ([]byte, e
return []byte{}, err
}

// Throw error if path was not created
if _, err := os.Stat(path); os.IsNotExist(err) {
return []byte{}, err
}

// Zip directory containing downloaded git repo
if err := ZipDir(path, zipPath); err != nil {
return []byte{}, err
Expand Down Expand Up @@ -208,6 +213,19 @@ func gitSubDir(srcPath, destinationPath, subDir string, fs filesystem.Filesystem
return err
}

// Create destinationPath if does not exist
if _, err = fs.Stat(destinationPath); os.IsNotExist(err) {
var srcinfo os.FileInfo

if srcinfo, err = fs.Stat(srcPath); err != nil {
return err
}

if err = fs.MkdirAll(destinationPath, srcinfo.Mode()); err != nil {
return err
}
}

// Loop over files.
for outputIndex := range outputDirFiles {
outputFileHere := outputDirFiles[outputIndex]
Expand Down
148 changes: 86 additions & 62 deletions index/generator/library/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,69 @@ func TestCloneRemoteStack(t *testing.T) {
wantErrStr string
}{
{
"Case 1: Maven Java (Without subDir)",
&schema.Git{
name: "Case 1: Maven Java",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
},
filepath.Join(os.TempDir(), "springboot-ex"),
false,
"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: false,
wantErrStr: "",
},
{
"Case 2: Maven Java (With subDir)",
&schema.Git{
name: "Case 2: Maven Java (With subDir)",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
SubDir: "src/main",
},
filepath.Join(os.TempDir(), "springboot-ex"),
false,
"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: false,
wantErrStr: "",
},
{
"Case 3: Maven Java - Cloning with Hash Revision",
&schema.Git{
name: "Case 3: Wildfly Java - microprofile-config subdirectory",
git: &schema.Git{
Url: "https://github.com/wildfly/quickstart.git",
RemoteName: "wildfly-quickstart",
Revision: "22.0.1.Final",
SubDir: "microprofile-config",
},
path: filepath.Join(os.TempDir(), "quickstart"),
wantErr: false,
wantErrStr: "",
},
{
name: "Case 4: Maven Java - Cloning with Hash Revision",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
Revision: "694e96286ffdc3a9990d0041637d32cecba38181",
},
filepath.Join(os.TempDir(), "springboot-ex"),
true,
"specifying commit in 'revision' is not yet supported",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: true,
wantErrStr: "specifying commit in 'revision' is not yet supported",
},
{
"Case 4: Cloning a non-existant repo",
&schema.Git{
name: "Case 5: Cloning a non-existent repo",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/nonexist.git",
RemoteName: "origin",
},
filepath.Join(os.TempDir(), "nonexist"),
true,
"",
path: filepath.Join(os.TempDir(), "nonexist"),
wantErr: true,
wantErrStr: "",
},
{
"Case 5: Maven Java - Cloning with Invalid Revision",
&schema.Git{
name: "Case 6: Maven Java - Cloning with Invalid Revision",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
Revision: "invalid",
},
filepath.Join(os.TempDir(), "springboot-ex"),
true,
"couldn't find remote ref \"refs/tags/invalid\"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: true,
wantErrStr: "couldn't find remote ref \"refs/tags/invalid\"",
},
}

Expand Down Expand Up @@ -110,34 +122,34 @@ func TestDownloadStackFromZipUrl(t *testing.T) {
wantErrStr string
}{
{
"Case 1: Java Quarkus (Without subDir)",
map[string]string{
name: "Case 1: Java Quarkus",
params: map[string]string{
"Name": "quarkus",
"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",
"SubDir": "",
},
false,
"",
wantErr: false,
wantErrStr: "",
},
{
"Case 2: Java Quarkus (With subDir)",
map[string]string{
name: "Case 2: Java Quarkus (With subDir)",
params: map[string]string{
"Name": "quarkus",
"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",
"SubDir": "src",
},
false,
"",
wantErr: false,
wantErrStr: "",
},
{
"Case 3: Download error",
map[string]string{
name: "Case 3: Download error",
params: map[string]string{
"Name": "quarkus",
"ZipUrl": "https://code.quarkus.io/d?e=io.quarkus",
"SubDir": "",
},
true,
"failed to retrieve https://code.quarkus.io/d?e=io.quarkus, 400: Bad Request",
wantErr: true,
wantErrStr: "failed to retrieve https://code.quarkus.io/d?e=io.quarkus, 400: Bad Request",
},
}

Expand Down Expand Up @@ -179,57 +191,69 @@ func TestDownloadStackFromGit(t *testing.T) {
wantErrStr string
}{
{
"Case 1: Maven Java (Without subDir)",
&schema.Git{
name: "Case 1: Maven Java",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
},
filepath.Join(os.TempDir(), "springboot-ex"),
false,
"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: false,
wantErrStr: "",
},
{
"Case 2: Maven Java (With subDir)",
&schema.Git{
name: "Case 2: Maven Java (With subDir)",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
SubDir: "src/main",
},
filepath.Join(os.TempDir(), "springboot-ex-main"),
false,
"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: false,
wantErrStr: "",
},
{
name: "Case 3: Wildfly Java - microprofile-config subdirectory",
git: &schema.Git{
Url: "https://github.com/wildfly/quickstart.git",
RemoteName: "wildfly-quickstart",
Revision: "22.0.1.Final",
SubDir: "microprofile-config",
},
path: filepath.Join(os.TempDir(), "quickstart"),
wantErr: false,
wantErrStr: "",
},
{
"Case 3: Maven Java - Cloning with Hash Revision",
&schema.Git{
name: "Case 4: Maven Java - Cloning with Hash Revision",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
Revision: "694e96286ffdc3a9990d0041637d32cecba38181",
},
filepath.Join(os.TempDir(), "springboot-ex"),
true,
"specifying commit in 'revision' is not yet supported",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: true,
wantErrStr: "specifying commit in 'revision' is not yet supported",
},
{
"Case 4: Cloning a non-existant repo",
&schema.Git{
name: "Case 5: Cloning a non-existent repo",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/nonexist.git",
RemoteName: "origin",
},
filepath.Join(os.TempDir(), "nonexist"),
true,
"",
path: filepath.Join(os.TempDir(), "nonexist"),
wantErr: true,
wantErrStr: "",
},
{
"Case 5: Maven Java - Cloning with Invalid Revision",
&schema.Git{
name: "Case 6: Maven Java - Cloning with Invalid Revision",
git: &schema.Git{
Url: "https://github.com/odo-devfiles/springboot-ex.git",
RemoteName: "origin",
Revision: "invalid",
},
filepath.Join(os.TempDir(), "springboot-ex"),
true,
"couldn't find remote ref \"refs/tags/invalid\"",
path: filepath.Join(os.TempDir(), "springboot-ex"),
wantErr: true,
wantErrStr: "couldn't find remote ref \"refs/tags/invalid\"",
},
}

Expand Down