From 892b6aad3940e33911e8b7393877a68d971d9ca7 Mon Sep 17 00:00:00 2001 From: kmetin Date: Thu, 24 Aug 2023 12:46:42 +0300 Subject: [PATCH] use temp home path for project list tests --- base/commands/project/project_list_it_test.go | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/base/commands/project/project_list_it_test.go b/base/commands/project/project_list_it_test.go index 1ce1551d..e48eb0c1 100644 --- a/base/commands/project/project_list_it_test.go +++ b/base/commands/project/project_list_it_test.go @@ -30,43 +30,38 @@ func TestProjectListCommand(t *testing.T) { } func projectList_CachedTest(t *testing.T) { - testDir := filepath.Join(check.MustValue(filepath.Abs("testdata"))) - home := filepath.Join(testDir, "home") - sPath := filepath.Join(home, storeFolder) - sa := store.NewStoreAccessor(sPath, log.NopLogger{}) - check.MustValue(sa.WithLock(func(s *store.Store) (any, error) { - err := s.SetEntry(bytes(nextFetchTimeKey), - bytes(strconv.FormatInt(time.Now().Add(cacheRefreshInterval).Unix(), 10))) - return nil, err - })) - check.MustValue(sa.WithLock(func(s *store.Store) (any, error) { - b, err := json.Marshal([]Template{{Name: "test_template"}}) - check.Must(err) - err = s.SetEntry(bytes(templatesKey), b) - return nil, err - })) tcx := it.TestContext{T: t} tcx.Tester(func(tcx it.TestContext) { - it.WithEnv(paths.EnvCLCHome, home, func() { - cmd := []string{"project", "list-templates"} - check.Must(tcx.CLC().Execute(context.Background(), cmd...)) - tcx.AssertStdoutContains("test_template") - defer func() { - os.RemoveAll(sPath) - }() - }) + sPath := filepath.Join(tcx.HomePath(), storeFolder) + sa := store.NewStoreAccessor(sPath, log.NopLogger{}) + check.MustValue(sa.WithLock(func(s *store.Store) (any, error) { + err := s.SetEntry(bytes(nextFetchTimeKey), + bytes(strconv.FormatInt(time.Now().Add(cacheRefreshInterval).Unix(), 10))) + return nil, err + })) + check.MustValue(sa.WithLock(func(s *store.Store) (any, error) { + b, err := json.Marshal([]Template{{Name: "test_template"}}) + check.Must(err) + err = s.SetEntry(bytes(templatesKey), b) + return nil, err + })) + cmd := []string{"project", "list-templates"} + check.Must(tcx.CLC().Execute(context.Background(), cmd...)) + tcx.AssertStdoutContains("test_template") + defer func() { + os.RemoveAll(sPath) + }() }) } func projectList_LocalTest(t *testing.T) { - testDir := filepath.Join(check.MustValue(filepath.Abs("testdata"))) - home := filepath.Join(testDir, "home") tcx := it.TestContext{T: t} tcx.Tester(func(tcx it.TestContext) { - it.WithEnv(paths.EnvCLCHome, home, func() { - cmd := []string{"project", "list-templates", "--local"} - check.Must(tcx.CLC().Execute(context.Background(), cmd...)) - tcx.AssertStdoutContains("simple") - }) + testHomeDir := "testdata/home" + check.Must(paths.CopyDir(testHomeDir, tcx.HomePath())) + cmd := []string{"project", "list-templates", "--local"} + check.Must(tcx.CLC().Execute(context.Background(), cmd...)) + tcx.AssertStdoutContains("simple") + tcx.AssertStdoutContains("local") }) }