@@ -31,6 +31,12 @@ func init() {
3131 log .SetLevel (log .DebugLevel )
3232}
3333
34+ func fatalError (t * testing.T , err error ) {
35+ if err != nil {
36+ t .Fatal (err )
37+ }
38+ }
39+
3440func TestServerMethsTempl (t * testing.T ) {
3541 const def = `
3642 syntax = "proto3";
@@ -63,19 +69,16 @@ func TestServerMethsTempl(t *testing.T) {
6369 }
6470 `
6571 sd , err := svcdef .NewFromString (def , gopath )
66- if err != nil {
67- t .Fatal (err )
68- }
72+ fatalError (t , err )
6973
7074 var he handlerData
7175 he .Methods = sd .Service .Methods
7276 he .ServiceName = sd .Service .Name
7377
7478 gen , err := applyServerMethsTempl (he )
75- if err != nil {
76- t .Fatal (err )
77- }
79+ fatalError (t , err )
7880 genBytes , err := ioutil .ReadAll (gen )
81+ fatalError (t , err )
7982 const expected = `
8083 func (s Service) ProtoMethod(ctx context.Context, in *pb.RequestMessage) (*pb.ResponseMessage, error){
8184 var resp pb.ResponseMessage
@@ -124,13 +127,14 @@ func TestApplyServerTempl(t *testing.T) {
124127 PBPackage : "github.com/DoNewsCode/truss/gengokit/general-service" ,
125128 }
126129 sd , err := svcdef .NewFromString (def , gopath )
127- if err != nil {
128- t .Fatal (err )
129- }
130+ fatalError (t , err )
130131 te , err := gengokit .NewData (sd , conf )
132+ fatalError (t , err )
131133
132134 gen , err := applyServerTempl (te )
135+ fatalError (t , err )
133136 genBytes , err := ioutil .ReadAll (gen )
137+ fatalError (t , err )
134138 expected := `
135139 package proto
136140
@@ -212,9 +216,7 @@ func TestIsValidFunc(t *testing.T) {
212216 }
213217 `
214218 sd , err := svcdef .NewFromString (def , gopath )
215- if err != nil {
216- t .Fatal (err )
217- }
219+ fatalError (t , err )
218220
219221 m := newMethodMap (sd .Service .Methods )
220222 const validUnexported = `package p;
@@ -297,9 +299,7 @@ func TestPruneDecls(t *testing.T) {
297299 }
298300 `
299301 sd , err := svcdef .NewFromString (def , gopath )
300- if err != nil {
301- t .Fatal (err )
302- }
302+ fatalError (t , err )
303303
304304 m := newMethodMap (sd .Service .Methods )
305305
@@ -429,9 +429,7 @@ func TestUpdateMethods(t *testing.T) {
429429 `
430430
431431 sd , err := svcdef .NewFromString (def , gopath )
432- if err != nil {
433- t .Fatal (err )
434- }
432+ fatalError (t , err )
435433
436434 svc := sd .Service
437435 allMethods := svc .Methods
@@ -442,21 +440,15 @@ func TestUpdateMethods(t *testing.T) {
442440 }
443441
444442 te , err := gengokit .NewData (sd , conf )
445- if err != nil {
446- t .Fatal (err )
447- }
443+ fatalError (t , err )
448444
449445 svc .Methods = []* svcdef.ServiceMethod {allMethods [0 ]}
450446
451447 firstCode , err := renderService (svc , "" , te )
452- if err != nil {
453- t .Fatal (err )
454- }
448+ fatalError (t , err )
455449
456450 secondCode , err := renderService (svc , firstCode , te )
457- if err != nil {
458- t .Fatal (err )
459- }
451+ fatalError (t , err )
460452
461453 if len (firstCode ) != len (secondCode ) {
462454 t .Fatal ("Generated service differs after regenerated with same definition\n " +
@@ -466,9 +458,7 @@ func TestUpdateMethods(t *testing.T) {
466458 svc .Methods = append (svc .Methods , allMethods [1 ])
467459
468460 thirdCode , err := renderService (svc , secondCode , te )
469- if err != nil {
470- t .Fatal (err )
471- }
461+ fatalError (t , err )
472462
473463 if len (thirdCode ) <= len (secondCode ) {
474464 t .Fatal ("Generated service not longer after regenerated with additional service method\n " +
@@ -479,9 +469,7 @@ func TestUpdateMethods(t *testing.T) {
479469 svc .Methods = svc .Methods [1 :]
480470
481471 forthCode , err := renderService (svc , thirdCode , te )
482- if err != nil {
483- t .Fatal (err )
484- }
472+ fatalError (t , err )
485473
486474 if len (forthCode ) >= len (thirdCode ) {
487475 t .Fatal ("Generated service not shorter after regenerated with fewer service method\n " +
@@ -491,9 +479,7 @@ func TestUpdateMethods(t *testing.T) {
491479 svc .Methods = allMethods
492480
493481 fifthCode , err := renderService (svc , forthCode , te )
494- if err != nil {
495- t .Fatal (err )
496- }
482+ fatalError (t , err )
497483
498484 if len (fifthCode ) <= len (forthCode ) {
499485 t .Fatal ("Generated service not longer after regenerated with additional service method\n " +
0 commit comments