-
Notifications
You must be signed in to change notification settings - Fork 1
/
pairing_test.go
49 lines (40 loc) · 1.03 KB
/
pairing_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
package nodepair_test
import (
"context"
"os"
"time"
qr "github.com/kairos-io/go-nodepair/qrcode"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/skip2/go-qrcode"
nodepair "github.com/kairos-io/go-nodepair"
)
var _ = Describe("Pairing", func() {
token := nodepair.GenerateToken()
Context("Pairing", func() {
It("can pair arbitrary data", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
png, err := qrcode.Encode(token, qrcode.Medium, 1)
if err != nil {
return
}
f, _ := os.CreateTemp("", "xxx")
defer os.RemoveAll(f.Name())
os.WriteFile(f.Name(), png, os.ModePerm)
go func() {
time.Sleep(2 * time.Second)
if err := nodepair.Send(
ctx, map[string]string{"foo": "Bar"},
nodepair.WithReader(qr.Reader),
nodepair.WithToken(f.Name()),
); err != nil {
cancel()
}
}()
r := map[string]string{}
nodepair.Receive(ctx, &r, nodepair.WithToken(token))
Expect(r).To(Equal(map[string]string{"foo": "Bar"}))
})
})
})