better bash - unit and integration testing

24
@cjcjameson 1 Unit and Integration Testing C.J. Jameson Better Bash

Upload: cj-jameson

Post on 25-Jan-2017

432 views

Category:

Software


3 download

TRANSCRIPT

@cjcjameson1

Unit and Integration TestingC.J. Jameson

Better Bash

@cjcjameson

I work at Pivotal, I’m a Toolsmith, I tweet some

2

@cjcjameson3

Customer = EngineerReliability & predictable outcomes

Good bug reportsEager to make tradeoffs

@cjcjameson4

Tradeoffs?Customization vs. Reuse

User experience vs. Exposing internalsYAGNI

@cjcjameson

How good does this need to be?The tradeoff with your Bash scripts

5

effort

time

¯\_(ツ)_/¯ ...sorry dude

@cjcjameson6

Here’s my shiny tool…?

@cjcjameson

cover this square with an image (540 x 480 pixels)

7

STOPWhen would anyone write a test themselves?

@cjcjameson

cover this square with an image (540 x 480 pixels)

8

STOPWhen would anyone write a test themselves?

@cjcjameson

cover this square with an image (540 x 480 pixels)

9

STOPWhen would anyone runthe tests?

@cjcjameson10

When would anyone run the tests?

STOP

@cjcjameson11

When would anyone run the tests?

STOP

https://github.com/koalaman/shellcheck

@cjcjameson12 1https://en.wikipedia.org/wiki/Unit_testing

In general, unit tests...1

Find problems early Make change easy

Drive modular designAre documentationMake integration easy

@cjcjameson13

You’re writing an installer file

Be documentationMake integration easy(esp. across distros)

So your unit tests should help:

@cjcjameson14

You’re touching this code for the first and only time

Drive modular designMake change easy

So your unit tests should help:

Be documentation

@cjcjameson15

You’re treating the filesystem as a first-class object

Drive modular designFind problems early

So your unit tests should help:

@cjcjameson16

You’re writing a shared `common.bash` library

Be documentationMake integration easy

So your unit tests should help:

@cjcjameson17

You’re crafting a CLI user experience

Make change easyFind problems early

So your unit tests should help:

@cjcjameson18

Example: ruby-build

@cjcjameson19

Example: Concourse’s `git-resource`

https://ci.concourse.ci/pipelines/resources/jobs/git-resource

@cjcjameson20

Example: “Check the executable bit”

@cjcjameson21

Example: “Check the executable bit”

@cjcjameson22

Example: “Check the executable bit” - integration

@cjcjameson23

Inside the BATS `run` commandhttps://github.com/sstephenson/bats

- Exit codes are swallowed

- `stdout` and `stderr` are swallowed

- Start by `source`ing in the file under test … so the file runs

@cjcjameson24

Thanks!