Skip to content

Commit 2f6bcbe

Browse files
committed
feat: add support for sourcing local harvester config
1 parent 83101ce commit 2f6bcbe

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/console/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
7070
}
7171

7272
func 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

pkg/console/util_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package console
22

33
import (
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\nwant: %q", got, want)
38+
}
39+
}
40+
1741
func TestGetSSHKeysFromURL(t *testing.T) {
1842
testCases := []struct {
1943
name string

0 commit comments

Comments
 (0)