MCPcopy Create free account
hub / github.com/google/go-cloud / TestProcessOrder

Function TestProcessOrder

samples/order/processor_test.go:57–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestProcessOrder(t *testing.T) {
58 _, p, cleanup, err := setup(testConfig("ProcessOrder"))
59 if err != nil {
60 t.Fatal(err)
61 }
62 defer cleanup()
63
64 ctx := context.Background()
65 for _, test := range []struct {
66 filename string
67 want *Order
68 wantErr bool
69 }{
70 {
71 "cat1",
72 &Order{
73 ID: "cat1",
74 Email: "joe@example.com",
75 InImage: "cat1",
76 OutImage: "cat1-out.png",
77 Note: "converted from jpeg to png",
78 },
79 false,
80 },
81 {
82 "bad-image",
83 nil,
84 true,
85 },
86 } {
87 if err := copyFileToBucket("testdata/"+test.filename, p.bucket); err != nil {
88 t.Fatal(err)
89 }
90 got := &Order{
91 ID: test.filename,
92 Email: "joe@example.com",
93 InImage: test.filename,
94 }
95 err := p.processOrder(ctx, got)
96 if err == nil && test.wantErr {
97 t.Errorf("%s: got nil, want error", test.filename)
98 } else if err != nil && !test.wantErr {
99 t.Errorf("%s: got error %v, want nil", test.filename, err)
100 } else if err == nil && !cmp.Equal(got, test.want) {
101 t.Errorf("%s:\ngot %+v\nwant %+v", test.filename, got, test.want)
102 }
103 }
104}
105
106func copyFileToBucket(filename string, bucket *blob.Bucket) (err error) {
107 f, err := os.Open(filename)

Callers

nothing calls this directly

Calls 4

testConfigFunction · 0.85
copyFileToBucketFunction · 0.85
processOrderMethod · 0.80
setupFunction · 0.70

Tested by

no test coverage detected