stripe / skycfg

Skycfg is an extension library for the Starlark language that adds support for constructing Protocol Buffer messages.
Apache License 2.0
648 stars 54 forks source link

Simplify tests with runSkycfgTests test runner #98

Closed seena-stripe closed 3 years ago

seena-stripe commented 3 years ago

Summary

Adds a test runner runSkycfgTests to remove redundant testing logic. Many of the tests had a 1 line skycfg expression and a 1 line desired output, but duplicated all the test boilerplate, so this PR adds a test runner to simplify setting up a new test

This is purely cleanup and shouldn't affect evaluation.

Example

 func TestUnsetProto2Fields(t *testing.T) {
        // Proto v2 distinguishes between unset and set-to-empty.
-       msg, err := eval(`proto.package("skycfg.test_proto").MessageV2(
-                f_string = None,
-        )`, nil)
-       if err != nil {
-               t.Fatal(err)
-       }
-       got := mustProtoMessage(t, msg)
-       want := &pb.MessageV2{
-               FString: nil,
-       }
-       checkProtoEqual(t, want, got)
+       runSkycfgTests(t, []skycfgTest{
+               {
+                       src: `proto.package("skycfg.test_proto").MessageV2(
+                               f_string = None,
+                       )`,
+                       want: &pb.MessageV2{
+                               FString: nil,
+                       },
+               },
+       })
 }

This doesn't save on LoC very much but reduces the boilerplate so the test code is a lot more signalful and test output is consistent