diff --git a/.gitignore b/.gitignore index d6b4dbd..fdd5d50 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ drone-zip drone-zip* .DS_Store +test* \ No newline at end of file diff --git a/plugin.go b/plugin.go index 1563e00..f58571a 100644 --- a/plugin.go +++ b/plugin.go @@ -89,7 +89,7 @@ func IsDir(path string) bool { } func getFilePaths(path string) []string { - var paths []string + var paths, resultPaths []string var patternPath string if IsDir(path) { @@ -106,11 +106,11 @@ func getFilePaths(path string) []string { paths = append(paths, globedPaths...) // remove directory - for i, path := range paths { - if IsDir(path) { - paths = append(paths[:i], paths[i+1:]...) + for _, path := range paths { + if !IsDir(path) { + resultPaths = append(resultPaths, path) } } - return paths + return resultPaths } diff --git a/plugin_test.go b/plugin_test.go index 8fa2f9f..f9fb190 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -117,10 +117,53 @@ func TestPlugin(t *testing.T) { } +// issue#6 +func TestOutput(t *testing.T) { + t.Run("zip file output dir", func(t *testing.T) { + tmpDir := t.TempDir() + t.Logf("tmpDir: %v", tmpDir) + p := Plugin{ + Input: []string{"test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f"}, + Output: filepath.Join(tmpDir, "output-9071a1942d0d334aa224a1370d98e18015782d6f.zip"), + } + p.Exec() + + assert.Equal( + t, + []string{ + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/404.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/begriffe.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/datenschutz.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/feed_rss_created.xml", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/feed_rss_updated.xml", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/impressum.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/index.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/sitemap.xml", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/sitemap.xml.gz", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/index.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/1.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/2.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/3.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/index.html", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/search/search_index.js", + "test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/search/search_index.json", + }, + zipFiles(t, filepath.Join(tmpDir, "output-9071a1942d0d334aa224a1370d98e18015782d6f.zip")), + ) + }) +} + func zipFiles(t *testing.T, path string) []string { t.Helper() f, err := os.Open(path) - assert.NoError(t, err) + if err != nil { + t.Fatal(err) + } + defer func() { + if err := f.Close(); err != nil { + t.Fatal(err) + } + }() info, err := f.Stat() assert.NoError(t, err) r, err := zip.NewReader(f, info.Size()) diff --git a/scripts/generate-test-files.sh b/scripts/generate-test-files.sh index 6095ff8..aff2b3f 100755 --- a/scripts/generate-test-files.sh +++ b/scripts/generate-test-files.sh @@ -6,3 +6,24 @@ touch test/foo/a.js touch test/foo/b.txt touch test/a.txt touch test/b.js + + +# issues #6 +mkdir -p test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/404.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/begriffe.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/datenschutz.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/feed_rss_created.xml +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/feed_rss_updated.xml +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/impressum.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/index.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/index.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/1.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/2.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/3.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/rechtsformen/test/index.html +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/sitemap.xml +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/sitemap.xml.gz +mkdir -p test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/search +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/search/search_index.js +touch test-output/output-9071a1942d0d334aa224a1370d98e18015782d6f/search/search_index.json \ No newline at end of file