-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext_test.go
75 lines (61 loc) · 2 KB
/
context_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package azfunc
import (
"net/http"
"testing"
"github.com/KarlGW/azfunc/data"
"github.com/KarlGW/azfunc/output"
"github.com/google/go-cmp/cmp"
)
func TestContext_Output_HTTP_Write(t *testing.T) {
ctx := Context{
Outputs: &outputs{},
}
ctx.Outputs.Add(output.NewHTTP())
ctx.Outputs.HTTP().Write([]byte(`{"message":"hello"}`))
want := output.NewHTTP(func(o *output.HTTPOptions) {
o.Body = data.Raw(`{"message":"hello"}`)
})
got := ctx.Outputs.HTTP()
if diff := cmp.Diff(want.Data(), got.Data(), cmp.AllowUnexported(output.HTTP{})); diff != "" {
t.Errorf("Write() = unexpected result (-want +got)\n%s\n", diff)
}
}
func TestContext_Output_HTTP_WriteHeader(t *testing.T) {
ctx := Context{
Outputs: &outputs{},
}
ctx.Outputs.Add(output.NewHTTP())
ctx.Outputs.HTTP().WriteHeader(http.StatusNotFound)
want := output.NewHTTP()
want.WriteHeader(http.StatusNotFound)
got := ctx.Outputs.HTTP()
if diff := cmp.Diff(want, got, cmp.AllowUnexported(output.HTTP{})); diff != "" {
t.Errorf("Write() = unexpected result (-want +got)\n%s\n", diff)
}
}
func TestContext_Output_HTTP_Header_Add(t *testing.T) {
ctx := Context{
Outputs: &outputs{},
}
ctx.Outputs.Add(output.NewHTTP())
ctx.Outputs.HTTP().Header().Add("Content-Type", "application/json")
want := output.NewHTTP()
want.Header().Add("Content-Type", "application/json")
got := ctx.Outputs.HTTP()
if diff := cmp.Diff(want.Header(), got.Header(), cmp.AllowUnexported(output.HTTP{})); diff != "" {
t.Errorf("Write() = unexpected result (-want +got)\n%s\n", diff)
}
}
func TestContext_Output_Trigger_Write(t *testing.T) {
ctx := Context{
Outputs: &outputs{},
}
ctx.Outputs.Add(output.NewGeneric("queue"))
ctx.Outputs.Binding("queue").Write([]byte(`{"message":"hello"}`))
got := ctx.Outputs.Binding("queue")
want := output.NewGeneric("queue")
want.Write([]byte(`{"message":"hello"}`))
if diff := cmp.Diff(want, got, cmp.AllowUnexported(output.Generic{})); diff != "" {
t.Errorf("Write() = unexpected result (-want +got)\n%s\n", diff)
}
}