Skip to content

Commit

Permalink
formats new binary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbrgs committed Oct 25, 2023
1 parent d5ed214 commit ba4a238
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions internal/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error {

// Downloads the given binary to the target directory
func downloadBinary(targetDir string, read io.ReaderAt, size int64) error {
klog.V(4).Infof("Downloading binary to %q", targetDir)
klog.V(4).Infof("Downloading binary to %q", targetDir)

in := io.NewSectionReader(read, 0, size)
buf := make([]byte, size)
Expand Down Expand Up @@ -210,8 +210,8 @@ func detectMIMEType(at io.ReaderAt) (string, error) {
type extractor func(targetDir string, read io.ReaderAt, size int64) error

var defaultExtractors = map[string]extractor{
"application/zip": extractZIP,
"application/x-gzip": extractTARGZ,
"application/zip": extractZIP,
"application/x-gzip": extractTARGZ,
"application/octet-stream": downloadBinary,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/installation/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func install(op installOperation, opts InstallOpts) error {

// Download License file from given URI and rename downloaded binary to plugin name
if op.platform.License != "" {
if err:= downloadLicenseFile(downloadStagingDir, op.platform.License); err != nil {
if err := downloadLicenseFile(downloadStagingDir, op.platform.License); err != nil {
return errors.Wrap(err, "failed downloading license file to installation directory")
}
if err := renameBinary(downloadStagingDir, op.platform.Bin); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions internal/installation/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ func Test_downloadLicenseFile(t *testing.T) {
wantErr bool
}{
{
name: "with valid uri",
name: "with valid uri",
extractDir: tmpDir.Root(),
uri: url,
uri: url,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := downloadLicenseFile(tt.extractDir, tt.uri); err != nil {
t.Error(err)
t.Error(err)
}
})
}
Expand All @@ -368,30 +368,30 @@ func Test_renameBinary(t *testing.T) {
wantErr bool
}{
{
name: "with valid plugin name",
name: "with valid plugin name",
extractDir: testFile,
plugin: "test",
wantErr: false,
plugin: "test",
wantErr: false,
},
{
name: "without valid plugin name",
name: "without valid plugin name",
extractDir: tmpDir.Root(),
plugin: "not valid",
wantErr: true,
plugin: "not valid",
wantErr: true,
},
{
name: "without binary",
name: "without binary",
extractDir: tmpDir.Root(),
plugin: "valid",
wantErr: true,
plugin: "valid",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := renameBinary(tt.extractDir, tt.plugin); (err != nil) != tt.wantErr {
t.Error(err)
t.Error(err)
}
})
}
}
}

0 comments on commit ba4a238

Please sign in to comment.