Skip to content

Commit

Permalink
refactor: Do not specifically download color scheme file (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin authored Apr 2, 2024
1 parent 5b7b8ad commit 46f2192
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 88 deletions.
12 changes: 2 additions & 10 deletions cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 0 additions & 23 deletions internal/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package file

import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down
55 changes: 0 additions & 55 deletions internal/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}

0 comments on commit 46f2192

Please sign in to comment.