FirebaseExtended / protobuf-rules-gen

This is an experimental protoc plugin that generates Firebase Rules for Cloud Firestore based on Google's Protocol Buffer format. This allows you to easily validate your data in a platform independent manner.
Apache License 2.0
197 stars 13 forks source link

Add bazel macros for protobuf_rules_gen #29

Closed ribrdb closed 5 years ago

ribrdb commented 5 years ago

Here's a first stab at adding the BUILD rules. I'm not sure if you'd want to update the integration test to build using these rules or keep it completely separate.

I didn't include using the firestore emulator here. There's two reasons for that:

Once the emulator jar is available I basically just use a jasmine_node_test and add this to start the emulator:

beforeAll(async () => {
  return new Promise((resolve) => {
    console.log('Starting firestore emulator...');
    const child = child_process.spawn('java', [
      '-jar',
      '../com_google_cloud_firestore_emulator/jar/cloud-firestore-emulator.jar'
    ]);
    child.stdout.on('data', (data) => {
      console.log(`emulator: ${data}`);
      if (/localhost:8080/.test(data)) {
        console.log('Emulator alive!');
        resolve();
      }
    });

    child.stderr.on('data', (data) => {
      console.error(`emulator: ${data}`);
    });
    emulator = child;
  });
});
afterAll(() => {
  emulator.kill();
});
ribrdb commented 5 years ago

Hmm, I guess the CI is using an even older version of Bazel than I am. Should I update the rules to work with Bazel 0.9.0, or update the CI to use a newer version?

ribrdb commented 5 years ago

I've been trying to write a test using the firestore emulator, but I'm having lots of problems with it. It seems flaky. The same test case will sometimes pass, sometimes time out, or sometimes return a permission denied error. I guess for now I'll just add a golden file test.

rockwotj commented 5 years ago

Happy to take a look at a version that your experiencing flakiness with.

The emulator should be robust!

ribrdb commented 5 years ago

Happy to take a look at a version that your experiencing flakiness with.

The emulator should be robust!

https://github.com/ribrdb/protobuf-rules-gen/blob/emulator/example/rules_test.js

rockwotj commented 5 years ago

Thank you for your contribution!