From 134c19cfc2286a621aa28d25313d5821283cff9d Mon Sep 17 00:00:00 2001 From: Marcus Kok Date: Fri, 5 Apr 2024 12:29:24 -0400 Subject: [PATCH] fixing all tests --- cmd/init.go | 11 ++++++----- test/init_test.go | 5 +++-- test/link_test.go | 1 - 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index d280648..3417bf9 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -55,6 +55,7 @@ func runInitCommand(cmd *cobra.Command, args []string) { fs := FileSystem // if user has passed a dotfile path flag need to add it to // viper's search path for a config file + testing := viper.GetBool("testing") viper.AddConfigPath(filepath.Join(DotfilePath, "dotctl")) if(viper.Get("testing") == true && fs.Name() != "MemMapFS") { @@ -71,12 +72,12 @@ func runInitCommand(cmd *cobra.Command, args []string) { panic(fmt.Errorf("Unable to create config file %w", err)) } - err = viper.WriteConfig() - if err != nil && viper.Get("testing") != true { - log.Fatalf("Unable to write config on init: %s\n", err) - } + if !testing { + err = viper.WriteConfig() + if err != nil && viper.Get("testing") != true { + log.Fatalf("Unable to write config on init: %s\n", err) + } - if (viper.Get("testing") != "true"){ _, err = git.PlainInit(DotfilePath, false) if err != nil { log.Fatal(err) diff --git a/test/init_test.go b/test/init_test.go index 96f7fce..414e3eb 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -2,6 +2,7 @@ package test import ( "bytes" + "os" "path/filepath" "testing" @@ -20,11 +21,11 @@ func TestInitCommand(t *testing.T) { dotctl.SetOut(actual) dotctl.SetErr(actual) - dotctl.SetArgs([]string{"init", "--dotfile-path=dotctl_test/dotfiles"}) + dotctl.SetArgs([]string{"init"}) dotctl.Execute() - homedir := "dotctl_test/" + homedir := os.Getenv("HOME") _, err := afero.ReadFile(fs, filepath.Join(homedir, "dotfiles/dotctl/config")) if err != nil { diff --git a/test/link_test.go b/test/link_test.go index 657a83f..3dcd3f4 100644 --- a/test/link_test.go +++ b/test/link_test.go @@ -41,6 +41,5 @@ func TestLinkCommand(t *testing.T) { expected := fmt.Sprintf("%s,%s", someconfig, somedot) assert.Equal(t, expected, actual.String(), "actual differs from expected") - }