-
Notifications
You must be signed in to change notification settings - Fork 5
/
log_test.go
61 lines (53 loc) · 1.32 KB
/
log_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package lastpass_test
import (
"context"
"fmt"
"log"
"net/http"
"strings"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
. "github.com/ansd/lastpass-go"
)
var _ = Describe("Log", func() {
var server *ghttp.Server
var logger Logger
var logs strings.Builder
var err error
var user string
var passwd string
BeforeEach(func() {
user = readFile("user.txt")
passwd = readFile("passwd.txt")
server = ghttp.NewServer()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodPost, EndpointLogin),
ghttp.RespondWith(http.StatusOK, fmt.Sprintf("<ok token=\"%s\" privatekeyenc=\"%s\" />",
"fakeToken", readFile("privatekeyencrypted.txt"))),
),
)
logger = log.New(&logs, "", 0)
})
AfterEach(func() {
Expect(err).NotTo(HaveOccurred())
Expect(logs.String()).To(MatchRegexp(`^POST http://127\.0\.0\.1:[0-9]{1,5}/login\.php`))
server.Close()
})
Describe("NewContextWithLogger()", func() {
It("writes logs", func() {
_, err = NewClient(
NewContextWithLogger(context.Background(), logger),
user, passwd,
WithBaseURL(server.URL()))
})
})
Describe("WithLogger()", func() {
It("writes logs", func() {
_, err = NewClient(context.Background(), user, passwd,
WithBaseURL(server.URL()),
WithLogger(logger))
})
})
})