File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
7070}
7171
7272func getURL (client http.Client , url string ) ([]byte , error ) {
73+ if filePath , hasPrefix := strings .CutPrefix (url , "file://" ); hasPrefix {
74+ return os .ReadFile (filePath )
75+ }
76+
7377 resp , err := client .Get (url )
7478 if err != nil {
7579 return nil , err
Original file line number Diff line number Diff line change 11package console
22
33import (
4+ "bytes"
45 "errors"
56 "fmt"
67 "net"
78 "net/http"
89 "net/http/httptest"
10+ "os"
11+ "path/filepath"
912 "testing"
1013
1114 "github.com/stretchr/testify/assert"
@@ -14,6 +17,27 @@ import (
1417 "github.com/harvester/harvester-installer/pkg/util"
1518)
1619
20+ func TestGetURL_FileScheme (t * testing.T ) {
21+ t .Parallel ()
22+
23+ dir := t .TempDir ()
24+ filePath := filepath .Join (dir , "sample.txt" )
25+ want := []byte ("hello from disk" )
26+
27+ if err := os .WriteFile (filePath , want , 0o600 ); err != nil {
28+ t .Fatalf ("failed to write temp file: %v" , err )
29+ }
30+
31+ got , err := getURL (http.Client {}, "file://" + filePath )
32+ if err != nil {
33+ t .Fatalf ("getURL returned error: %v" , err )
34+ }
35+
36+ if ! bytes .Equal (got , want ) {
37+ t .Fatalf ("unexpected body:\n got: %q\n want: %q" , got , want )
38+ }
39+ }
40+
1741func TestGetSSHKeysFromURL (t * testing.T ) {
1842 testCases := []struct {
1943 name string
You can’t perform that action at this time.
0 commit comments