-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify_test.go
58 lines (45 loc) · 1.07 KB
/
minify_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
package events
import (
"context"
"encoding/json"
"testing"
"github.com/go-kit/kit/endpoint"
"github.com/stretchr/testify/assert"
)
func debugMiddleware(ack chan<- any) endpoint.Endpoint {
return func(ctx context.Context, request any) (any, error) {
go func(ack chan<- any) {
ack <- request
}(ack)
return nil, nil
}
}
func TestMinifyMiddleware(t *testing.T) {
assert := assert.New(t)
ack := make(chan any)
endpoint := debugMiddleware(ack)
endpoint = MinifyMiddleware()(endpoint)
input := []byte(`{
"message": "Hello World",
"timestamp": "2023-01-22T23:35:00.000+08:00"
}`)
req := StoreRequest{
Topic: "hello/world",
Payload: Payload{
Data: json.RawMessage(input),
Type: JSON,
},
}
endpoint(context.Background(), req)
request := <-ack
req, ok := request.(StoreRequest)
if !ok {
assert.Fail("invalid type")
return
}
expected := `{"message":"Hello World","timestamp":"2023-01-22T23:35:00.000+08:00"}`
actual, ok := req.Payload.JSON()
assert.True(ok)
assert.Equal(expected, string(actual))
assert.True(len(actual) <= len(input))
}