From 46f2192c97793529c79e7655cbdfc424f472e51f Mon Sep 17 00:00:00 2001 From: Robin Gagnon Date: Tue, 2 Apr 2024 12:52:20 -0500 Subject: [PATCH] refactor: Do not specifically download color scheme file (#59) --- cli/generate.go | 12 ++------- internal/file/file.go | 23 ---------------- internal/file/file_test.go | 55 -------------------------------------- 3 files changed, 2 insertions(+), 88 deletions(-) diff --git a/cli/generate.go b/cli/generate.go index aa13868..8227aca 100644 --- a/cli/generate.go +++ b/cli/generate.go @@ -73,14 +73,6 @@ func Generate(force bool, debug bool, repoKey string) bson.M { } for index, vimColorScheme := range repository.VimColorSchemes { - err = file.DownloadFile( - vimColorScheme.FileURL, - fmt.Sprintf("%s/colors/%s%s", tmpDirectoryPath, vimColorScheme.Name, filepath.Ext(vimColorScheme.FileURL)), - ) - if err != nil { - continue - } - var backgrounds []string lightVimColorSchemeColors, lightErr := getVimColorSchemeColorData(vimColorScheme, repoHelper.LightBackground) @@ -120,7 +112,7 @@ func Generate(force bool, debug bool, repoKey string) bson.M { generateObject := getGenerateRepositoryObject(repository) database.UpsertRepository(repository.ID, generateObject) - err = deletePlugin(pluginPath) + err = deletePlugin() if err != nil { log.Print(err) continue @@ -241,7 +233,7 @@ func installPlugin(gitRepositoryURL string, path string) error { } // Clears all installation traces of the vim plugin -func deletePlugin(path string) error { +func deletePlugin() error { // Remove plugin specific runtimepath from .vimrc err := file.RemoveLinesInFile("let &runtimepath.*\" plugin runtimepath", vimrcPath) if err != nil { diff --git a/internal/file/file.go b/internal/file/file.go index a0a82d2..a406f55 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -2,7 +2,6 @@ package file import ( "fmt" - "io" "io/ioutil" "log" "net/http" @@ -31,28 +30,6 @@ func GetFilesWithExtensions(files []*github.RepositoryContent, extensions []stri return result } -// DownloadFile downloads a file from a URL at a local target path -func DownloadFile(fileURL string, target string) error { - out, err := os.Create(target) - if err != nil { - return err - } - defer out.Close() - - resp, err := http.Get(fileURL) - if err != nil { - return err - } - defer resp.Body.Close() - - _, err = io.Copy(out, resp.Body) - if err != nil { - return err - } - - return nil -} - // GetRemoteFileContent returns the file content of a file at a URL func GetRemoteFileContent(fileURL string) (string, error) { response, err := http.Get(fileURL) diff --git a/internal/file/file_test.go b/internal/file/file_test.go index 4ce2e0c..9a489c5 100644 --- a/internal/file/file_test.go +++ b/internal/file/file_test.go @@ -428,58 +428,3 @@ func TestRemoveLinesInFile(t *testing.T) { } }) } - -func TestDownloadFile(t *testing.T) { - t.Run("should download the file locally if the is valid", func(t *testing.T) { - cleanUp := setUp(t) - defer cleanUp(t) - - expectedFileContent := "file content" - - server := test.MockServer(expectedFileContent, http.StatusOK) - defer server.Close() - - err := DownloadFile(server.URL, target) - - if err != nil { - t.Errorf("Incorrect result for DownloadFile, got error: %s", err) - } - - // Check if file was downloaded - fileContent, err := GetLocalFileContent(target) - if err != nil { - t.Errorf("Incorrect result for DownloadFile, got error reading file: %s", err) - } - - if fileContent != expectedFileContent { - t.Errorf("Incorrect result for DownloadFile, got: %s, want: %s", fileContent, expectedFileContent) - } - }) - - t.Run("should return error if the is invalid", func(t *testing.T) { - cleanUp := setUp(t) - defer cleanUp(t) - - err := DownloadFile("Wrong ", target) - - if err == nil { - t.Error("Incorrect result for DownloadFile, got no error when was invalid") - } - }) - - t.Run("should return error if the target is invalid", func(t *testing.T) { - cleanUp := setUp(t) - defer cleanUp(t) - - server := test.MockServer("content", http.StatusOK) - defer server.Close() - - invalidTarget := ".." - - err := DownloadFile(server.URL, invalidTarget) - - if err == nil { - t.Error("Incorrect result for DownloadFile, got no error when target was invalid") - } - }) -}