-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from WillAbides/readcache2
file-locking cache
- Loading branch information
Showing
24 changed files
with
1,416 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
type cacheCmd struct { | ||
Clear cacheClearCmd `kong:"cmd,help='clear the cache'"` | ||
} | ||
|
||
type cacheClearCmd struct{} | ||
|
||
func (c *cacheClearCmd) Run(ctx *runContext) error { | ||
config, err := loadConfigFile(ctx, false) | ||
if err != nil { | ||
return err | ||
} | ||
return config.ClearCache() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/willabides/bindown/v3" | ||
) | ||
|
||
func Test_cacheClearCmd(t *testing.T) { | ||
servePath := filepath.FromSlash("../../testdata/downloadables/fooinroot.tar.gz") | ||
successServer := serveFile(t, servePath, "/foo/fooinroot.tar.gz", "") | ||
depURL := successServer.URL + "/foo/fooinroot.tar.gz" | ||
|
||
t.Run("removes populated cache", func(t *testing.T) { | ||
runner := newCmdRunner(t) | ||
// extract something to populate the cache | ||
runner.writeConfig(&bindown.Config{ | ||
URLChecksums: map[string]string{ | ||
depURL: "27dcce60d1ed72920a84dd4bc01e0bbd013e5a841660e9ee2e964e53fb83c0b3", | ||
}, | ||
Dependencies: map[string]*bindown.Dependency{ | ||
"foo": {URL: &depURL}, | ||
}, | ||
}) | ||
result := runner.run("extract", "foo") | ||
extractDir := result.getExtractDir() | ||
assert.FileExists(t, filepath.Join(extractDir, "foo")) | ||
result = runner.run("cache", "clear") | ||
result.assertState(resultState{}) | ||
assert.NoDirExists(t, extractDir) | ||
}) | ||
|
||
t.Run("does nothing if cache is empty", func(t *testing.T) { | ||
runner := newCmdRunner(t) | ||
runner.writeConfig(&bindown.Config{}) | ||
result := runner.run("cache", "clear") | ||
result.assertState(resultState{}) | ||
}) | ||
|
||
t.Run("errors on missing config", func(t *testing.T) { | ||
runner := newCmdRunner(t) | ||
result := runner.run("cache", "clear") | ||
result.assertState(resultState{ | ||
exit: 1, | ||
stderr: `no such file or directory`, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.