Skip to content

Commit

Permalink
fix windows thing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 8, 2024
1 parent 007a64f commit 15c04fc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/apiclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"path"
"runtime"
"strings"
"testing"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -41,7 +42,27 @@ func setupWithPrefix(urlPrefix string) (*http.ServeMux, string, func()) {
return mux, server.URL, server.Close
}

// toUNCPath converts a Windows file path to a UNC path.
func toUNCPath(path, serverName, shareName string) (string, error) {
colonIndex := strings.Index(path, ":")
if colonIndex == -1 {
return "", fmt.Errorf("invalid path format, missing drive letter: %s", path)
}

uncPath := fmt.Sprintf("//localhost/%s%s", shareName, path[colonIndex-1:colonIndex]+"$"+path[colonIndex+1:])

return uncPath, nil
}

func setupUnixSocketWithPrefix(socket string, urlPrefix string) (mux *http.ServeMux, serverURL string, teardown func()) {
var err error
if runtime.GOOS == "windows" {
socket, err = toUNCPath(socket, "localhost", "share")
if err != nil {
log.Fatalf("converting to UNC path: %s", err)
}
}

mux = http.NewServeMux()
baseURLPath := "/" + urlPrefix

Expand Down

0 comments on commit 15c04fc

Please sign in to comment.