looker/lookml-test-runner

Name: lookml-test-runner

Owner: looker

Description: An experimental test runner for LookML models.

Created: 2018-01-24 22:11:22.0

Updated: 2018-01-25 01:09:41.0

Pushed: 2018-01-25 21:33:02.0

Homepage:

Size: 29

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

LookML Test Runner

An experimental test runner for LookML models. Designed to be used with continuous integration services like Travis CI or Circle CI (or anything else).

:warning: This is an experimental project, provided as-is without support. It is in an early phase and breaking changes may occur without warning.

See the LICENSE for more details.

How to Set Up
  1. Create a Test Runner user in Looker

    Create a new user in Looker that will serve as a “machine user” to run tests. That user should have an administrator role.

    :warning: Currently this user needs to be an administrator. Future APIs from Looker will enable the use of a less-permissioned user for running tests.

    You'll also need to get API credentials for this user.

  2. Enable your chosen CI service on the Git repository associated with your LookML project.

  3. Add environment variables to the CI service:

    • LOOKER_TEST_RUNNER_CLIENT_ID

      client ID for test user

    • LOOKER_TEST_RUNNER_CLIENT_SECRET

      client secret for the test user

    • LOOKER_TEST_RUNNER_ENDPOINT

      the API endpoint to use for tests

  4. Add configuration files to your Git repository to configure the test runner:

    • Create a new file at the root of your repository called Gemfile. Add the following contents:

      ce "https://rubygems.org"
      
      "lookml-test-runner", git: "https://github.com/looker/lookml-test-runner.git"
      
    • Configure your CI service to use the test runner:

    • For Travis CI:

      In a file called .travis.yml

      ript: bundle exec lookml_tests
      
    • Create test files

      The test runner will find any file ending with .test.yml in your repository. For example: tests.test.yml.

      Here's an example file for a fictional model:

    • test: does anything work query: model: mymodel view: myexplore fields: [“myexplore.id”] sorts: [“myexplore.id asc”] limit: 1 assert: success

    • test: what about a bad field query: model: mymodel view: myexplore fields: [“myexplore.average_age”] limit: 1 assert: success

      est Options
      
st: ID still exists
ery:
model: mymodel
view: myexplore
fields: ["myexplore.id"]
sorts: ["myexplore.id asc"]
limit: 1
sert: success
Assertion types
Custom Tests

The YAML-based tests are meant to be a simple and easy-to-use way to get started testing and are editable from within the Looker IDE. If you have more complex tests you can still use this project to run them. Here's how:

You can use any Ruby test runner to run your custom tests. In our example, we'll use Test::Unit.

Create a Ruby file and add it to your project. In this example we've created a file called advanced_tests.rb:

ire "bundler/setup"
ire "minitest/autorun"
ire 'lookml/test'

s TestLookML < Minitest::Test
f setup
@runner = LookML::Test::Runner.runner
d

f test_basic
result = @runner.sdk.run_inline_query("json_detail", {
  model: "lookml_test_test_fun",
  view: "users",
  fields: ["users.id"],
  sorts: ["users.id asc"],
  limit: 1,
})
assert_equal(result.data[0]["users.id"].value, 1)
d

You can then use @runner.sdk to run any operations you want. The SDK will automatically be placed into the correct developer mode environment for your tests to run.

Then just modify the script in your CI configuration to bundle exec lookml_tests && bundle exec ruby advanced_tests.rb.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.