Skip to content

Commit

Permalink
Merge pull request #33 from bats-core/readme-update
Browse files Browse the repository at this point in the history
Readme update
  • Loading branch information
vincent-zurczak authored Aug 31, 2021
2 parents e3ea96e + c8e40b9 commit 6ccb9f6
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 9 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DETIK: DevOps e2e Testing in Kubernetes
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)]()
[![Build Status](https://travis-ci.org/bats-core/bats-detik.svg?branch=master)](https://travis-ci.org/bats-core/bats-detik)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/bats-core/bats-detik/blob/master/LICENSE)
![Build status](https://github.com/bats-core/bats-detik/actions/workflows/test.yml/badge.svg)

This repository provides utilities to **execute end-to-end tests** of applications in Kubernetes clusters. This includes performing actions on the cluster (with kubectl, oc - for OpenShift - or helm) and verifying assertions by using a natural language, or almost. This reduces the amount of advanced bash commands to master.

Expand Down Expand Up @@ -29,6 +29,7 @@ This kind of test is the ultimate set of verifications to run for a project, lon
* [Debugging Tests](#debugging-tests)
* [Linting](#linting)
* [Tips](#tips)
* [Beyond K8s assertions](#beyond-k8s-assertions)


## Objectives
Expand All @@ -47,9 +48,11 @@ This kind of test is the ultimate set of verifications to run for a project, lon

### Test files and result

This section shows how to write unit tests using this library and BATS.
This section shows how to write unit tests using this library and [BATS](https://github.com/bats-core/bats-core).

```bash
#!/usr/bin/env bats

load "lib/utils"
load "lib/detik"

Expand Down Expand Up @@ -91,30 +94,32 @@ DETIK_CLIENT_NAME="kubectl"
}
```

Running the command **bats my-tests.bats** would result in the following output...
Executing **bats my-tests.bats** would result in the [following output](doc/success.gif)...

```
```ada
bats my-tests.bats
1..2
✓ 1 verify the deployment
✓ 2 verify the undeployment
The command "bats my-tests.bats" exited with 0.
```

In case of error, it would show...
In case of error, [it would show](doc/failure.gif)...

```
```ada
bats my-tests.bats
1..2
✗ 1 verify the deployment
(in test file my-tests.bats, line 14)
`[ "$status" -eq 0 ]' failed
✓ 2 verify the undeployment
The command "bats my-tests.bats" exited with 1.
```

Since this project uses BATS, you can use **setup** and **teardown**
Since this project works with BATS, you can use **setup** and **teardown**
functions to prepare and clean after every test in a file.


Expand Down Expand Up @@ -357,7 +362,7 @@ There is a **debug** function in DETIK.
You can use it in your own tests. Debug traces are stored into **/tmp/detik/**.
There is one debug file per test file.

It is recommended to reset this file at beginning of every test file.
It is recommended to reset this file at the beginning of every test file.

```bash
#!/usr/bin/env bats
Expand Down Expand Up @@ -440,3 +445,18 @@ load "lib/linter"

1. **Do not use file descriptors 3 and 4 in your tests.**
They are already used by BATS. And 0, 1 and 2 are default file descriptors. Use 5, 6 and higher values.


## Beyond K8s assertions

End-to-end tests may involve much more than K8s assertions.
BATS and DETIK can be combined with other testing frameworks, such
as performance tests (e.g. with [Gatling](https://gatling.io) and
[JMeter](https://jmeter.apache.org)) or functional scenarios with user
interactions (e.g. with [Selenium](https://www.selenium.dev),
[Cypress](https://www.cypress.io) or [Robot Framework](https://robotframework.org/)).

To do so, you would need to have these tools colocated (in a same
VM, container or POD). Your BATS scenarios would then invoke the various
tools and verify assertions with BATS. Sky is the limit then: it all
depends on what you want to test.
Binary file added doc/failure.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions doc/failure.terminalizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# The configurations that used for the recording, feel free to edit them
config:

# Specify a command to be executed
# like `/bin/bash -l`, `ls`, or any other commands
# the default is bash for Linux
# or powershell.exe for Windows
command: bash -l

# Specify the current working directory path
# the default is the current working directory path
cwd: /home/workspace/my-app-deployment

# Export additional ENV variables
env:
recording: true

# Explicitly set the number of columns
# or use `auto` to take the current
# number of columns of your shell
cols: 80

# Explicitly set the number of rows
# or use `auto` to take the current
# number of rows of your shell
rows: 16

# Amount of times to repeat GIF
# If value is -1, play once
# If value is 0, loop indefinitely
# If value is a positive number, loop n times
repeat: 0

# Quality
# 1 - 100
quality: 100

# Delay between frames in ms
# If the value is `auto` use the actual recording delays
frameDelay: auto

# Maximum delay between frames in ms
# Ignored if the `frameDelay` isn't set to `auto`
# Set to `auto` to prevent limiting the max idle time
maxIdleTime: auto

# The surrounding frame box
# The `type` can be null, window, floating, or solid`
# To hide the title use the value null
# Don't forget to add a backgroundColor style with a null as type
frameBox:
type: null
title: null
style:
backgroundColor: black
# border: 0px black solid
# boxShadow: none
# margin: 0px

# Add a watermark image to the rendered gif
# You need to specify an absolute path for
# the image on your machine or a URL, and you can also
# add your own CSS styles
watermark:
imagePath: null
style:
position: absolute
right: 15px
bottom: 15px
width: 100px
opacity: 0.9

# Cursor style can be one of
# `block`, `underline`, or `bar`
cursorStyle: block

# Font family
# You can use any font that is installed on your machine
# in CSS-like syntax
fontFamily: "Monaco, Lucida Console, Ubuntu Mono, Monospace"

# The size of the font
fontSize: 20

# The height of lines
lineHeight: 1

# The spacing between letters
letterSpacing: 0

# Theme
theme:
background: "transparent"
foreground: "#afafaf"
cursor: "#c7c7c7"
black: "#232628"
red: "#ff0f1a"
green: "#b3e33b"
yellow: "#ffa727"
blue: "#75dff2"
magenta: "#ae89fe"
cyan: "#708387"
white: "#d5d5d0"
brightBlack: "#626566"
brightRed: "#ff7fac"
brightGreen: "#c8ed71"
brightYellow: "#ebdf86"
brightBlue: "#75dff2"
brightMagenta: "#ae89fe"
brightCyan: "#b1c6ca"
brightWhite: "#f9f9f4"

# Records, feel free to edit them
records:
- delay: 121
content: "\e[01;34m/home/workspace/my-app-deployment\e[00m$ "
- delay: 876
content: b
- delay: 208
content: a
- delay: 144
content: t
- delay: 112
content: s
- delay: 144
content: ' '
- delay: 146
content: e
- delay: 295
content: 2e/
- delay: 1239
content: "\r\n"
- delay: 23
content: "\e[1G\e[31m ✗ verify the deployment\e[K\r\n\e[0m\r\n\e[31m (in test file e2e/scenario-1.bats, line 14)\r\n\e[0m\e[31;22m `[ \"$status\" -eq 0 ]' failed\r\n\e[0m\e[1G\r\n ✓ verify the undeployment\e[K\r\n\e[0m\r\n2 tests, 1 failure\r\n\r\n\e]"
- delay: 12800
content: "\r\n"
Binary file added doc/success.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 148 additions & 0 deletions doc/success.terminalizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# The configurations that used for the recording, feel free to edit them
config:

# Specify a command to be executed
# like `/bin/bash -l`, `ls`, or any other commands
# the default is bash for Linux
# or powershell.exe for Windows
command: bash -l

# Specify the current working directory path
# the default is the current working directory path
cwd: /home/workspace/my-app-deployment

# Export additional ENV variables
env:
recording: true

# Explicitly set the number of columns
# or use `auto` to take the current
# number of columns of your shell
cols: 80

# Explicitly set the number of rows
# or use `auto` to take the current
# number of rows of your shell
rows: 16

# Amount of times to repeat GIF
# If value is -1, play once
# If value is 0, loop indefinitely
# If value is a positive number, loop n times
repeat: 0

# Quality
# 1 - 100
quality: 100

# Delay between frames in ms
# If the value is `auto` use the actual recording delays
frameDelay: auto

# Maximum delay between frames in ms
# Ignored if the `frameDelay` isn't set to `auto`
# Set to `auto` to prevent limiting the max idle time
maxIdleTime: 2000

# The surrounding frame box
# The `type` can be null, window, floating, or solid`
# To hide the title use the value null
# Don't forget to add a backgroundColor style with a null as type
frameBox:
type: null
title: null
style:
background-color: black
border: 0px black solid
# boxShadow: none
# margin: 0px

# Add a watermark image to the rendered gif
# You need to specify an absolute path for
# the image on your machine or a URL, and you can also
# add your own CSS styles
watermark:
imagePath: null
style:
position: absolute
right: 15px
bottom: 15px
width: 100px
opacity: 0.9

# Cursor style can be one of
# `block`, `underline`, or `bar`
cursorStyle: block

# Font family
# You can use any font that is installed on your machine
# in CSS-like syntax
fontFamily: "Monaco, Lucida Console, Ubuntu Mono, Monospace"

# The size of the font
fontSize: 20

# The height of lines
lineHeight: 1

# The spacing between letters
letterSpacing: 0

# Theme
theme:
background: "transparent"
foreground: "#afafaf"
cursor: "#c7c7c7"
black: "#232628"
red: "#fc4384"
green: "#b3e33b"
yellow: "#ffa727"
blue: "#75dff2"
magenta: "#ae89fe"
cyan: "#708387"
white: "#d5d5d0"
brightBlack: "#626566"
brightRed: "#ff7fac"
brightGreen: "#c8ed71"
brightYellow: "#ebdf86"
brightBlue: "#75dff2"
brightMagenta: "#ae89fe"
brightCyan: "#b1c6ca"
brightWhite: "#f9f9f4"

# Records, feel free to edit them
records:
- delay: 317
content: "\e[01;32m$\e[00m:\e[01;34m/home/workspace/my-app-deployment\e[00m$ "
- delay: 944
content: l
- delay: 161
content: s
- delay: 175
content: ' '
- delay: 112
content: e
- delay: 295
content: 2e/
- delay: 601
content: "\r\nscenario-1.bats\r\n\e]0;$:/home/workspace/my-app-deployment\e\\\e]7;file://Buzz/home/workspace/my-app-deployment\e\\\e]0;$: /home/workspace/my-app-deployment\a\e[01;32m$\e[00m:\e[01;34m/home/workspace/my-app-deployment\e[00m$ "
- delay: 1030
content: b
- delay: 128
content: a
- delay: 113
content: t
- delay: 112
content: s
- delay: 79
content: ' '
- delay: 144
content: e
- delay: 279
content: 2e/
- delay: 697
content: "\r\n"
- delay: 30
content: "\e[1G ✓ verify the deployment\e[K\r\n\e[0m\e[1G ✓ verify the undeployment\e[K\r\n\e[0m\r\n2 tests, 0 failures\r\n\r\n\e]0;"
- delay: 2800
content: "\r\n"

0 comments on commit 6ccb9f6

Please sign in to comment.