Skip to content

Commit ad21c01

Browse files
committed
logger: better url detection and test
1 parent c945d2e commit ad21c01

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

logger.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8+
"strings"
89
)
910

1011
// Logger is used to handle incoming logs from the ipfs node
@@ -28,8 +29,13 @@ func (l Logger) Close() error {
2829

2930
// GetLogs is used to retrieve a parsable logger object
3031
func (s *Shell) GetLogs() (Logger, error) {
31-
logURL := fmt.Sprintf("http://%s/api/v0/log/tail", s.url)
32-
req, err := http.NewRequest("GET", logURL, nil)
32+
var url string
33+
if !strings.HasPrefix(s.url, "http://") {
34+
url = fmt.Sprintf("http://%s/api/v0/log/tail", s.url)
35+
} else {
36+
url = s.url
37+
}
38+
req, err := http.NewRequest("GET", url, nil)
3339
if err != nil {
3440
return Logger{}, err
3541
}

logger_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package shell
22

3-
import "testing"
3+
import (
4+
"testing"
5+
)
46

57
func Test_Logger(t *testing.T) {
68
sh := NewLocalShell()
@@ -13,8 +15,9 @@ func Test_Logger(t *testing.T) {
1315
t.Fatal(err)
1416
}
1517
}()
16-
_, err = logger.Next()
17-
if err != nil {
18+
if l, err := logger.Next(); err != nil {
1819
t.Fatal(err)
20+
} else if l == nil {
21+
t.Fatal("no logs found")
1922
}
2023
}

0 commit comments

Comments
 (0)