add subcommands cache info cache cleanup

Signed-off-by: Quan TRAN <account@itscaro.me>
This commit is contained in:
Quan TRAN
2022-02-12 17:52:52 +09:00
committed by Yusuke Kuoka
parent cf02442591
commit 242e601898
4 changed files with 69 additions and 13 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ import (
const defaultCacheDir = "helmfile"
func cacheDir() string {
func CacheDir() string {
dir, err := os.UserCacheDir()
if err != nil {
// fall back to relative path with hidden directory
@@ -204,7 +204,7 @@ func (r *Remote) Fetch(goGetterSrc string, cacheDirOpt ...string) (string, error
// e.g. https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
getterDst := filepath.Join(cacheBaseDir, cacheKey)
// e.g. os.cacheDir()/helmfile/https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
// e.g. os.CacheDir()/helmfile/https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
cacheDirPath := filepath.Join(r.Home, getterDst)
r.Logger.Debugf("home: %s", r.Home)
@@ -292,7 +292,7 @@ func NewRemote(logger *zap.SugaredLogger, homeDir string, readFile func(string)
if remote.Home == "" {
// Use for remote charts
remote.Home = cacheDir()
remote.Home = CacheDir()
} else {
// Use for remote helmfiles, this case Home is relative to the processing file
remote.Home = filepath.Join(remote.Home, relativeCacheDir())
+10 -10
View File
@@ -13,10 +13,10 @@ import (
func TestRemote_HttpsGitHub(t *testing.T) {
cleanfs := map[string]string{
cacheDir(): "",
CacheDir(): "",
}
cachefs := map[string]string{
filepath.Join(cacheDir(), "https_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml"): "foo: bar",
filepath.Join(CacheDir(), "https_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml"): "foo: bar",
}
type testcase struct {
@@ -38,7 +38,7 @@ func TestRemote_HttpsGitHub(t *testing.T) {
hit := true
get := func(wd, src, dst string) error {
if wd != cacheDir() {
if wd != CacheDir() {
return fmt.Errorf("unexpected wd: %s", wd)
}
if src != "git::https://github.com/cloudposse/helmfiles.git?ref=0.40.0" {
@@ -55,7 +55,7 @@ func TestRemote_HttpsGitHub(t *testing.T) {
}
remote := &Remote{
Logger: helmexec.NewLogger(os.Stderr, "debug"),
Home: cacheDir(),
Home: CacheDir(),
Getter: getter,
ReadFile: testfs.ReadFile,
FileExists: testfs.FileExistsAt,
@@ -74,7 +74,7 @@ func TestRemote_HttpsGitHub(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
expectedFile := filepath.Join(cacheDir(), "https_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml")
expectedFile := filepath.Join(CacheDir(), "https_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml")
if file != expectedFile {
t.Errorf("unexpected file located: %s vs expected: %s", file, expectedFile)
}
@@ -91,10 +91,10 @@ func TestRemote_HttpsGitHub(t *testing.T) {
func TestRemote_SShGitHub(t *testing.T) {
cleanfs := map[string]string{
cacheDir(): "",
CacheDir(): "",
}
cachefs := map[string]string{
filepath.Join(cacheDir(), "ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml"): "foo: bar",
filepath.Join(CacheDir(), "ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml"): "foo: bar",
}
type testcase struct {
@@ -116,7 +116,7 @@ func TestRemote_SShGitHub(t *testing.T) {
hit := true
get := func(wd, src, dst string) error {
if wd != cacheDir() {
if wd != CacheDir() {
return fmt.Errorf("unexpected wd: %s", wd)
}
if src != "git::ssh://git@github.com/cloudposse/helmfiles.git?ref=0.40.0" {
@@ -133,7 +133,7 @@ func TestRemote_SShGitHub(t *testing.T) {
}
remote := &Remote{
Logger: helmexec.NewLogger(os.Stderr, "debug"),
Home: cacheDir(),
Home: CacheDir(),
Getter: getter,
ReadFile: testfs.ReadFile,
FileExists: testfs.FileExistsAt,
@@ -146,7 +146,7 @@ func TestRemote_SShGitHub(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
expectedFile := filepath.Join(cacheDir(), "ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml")
expectedFile := filepath.Join(CacheDir(), "ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml")
if file != expectedFile {
t.Errorf("unexpected file located: %s vs expected: %s", file, expectedFile)
}