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

fix: There is a logical error in getFilePaths #10

Merged
merged 2 commits into from
Sep 15, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ drone-zip
drone-zip*

.DS_Store
test*
10 changes: 5 additions & 5 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
45 changes: 44 additions & 1 deletion plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
21 changes: 21 additions & 0 deletions scripts/generate-test-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading