LoginSignup
2
1

More than 5 years have passed since last update.

テストツール goss導入・使用メモ

Last updated at Posted at 2017-04-17

Goss

メモ・感想

とりあえずつかってみたメモ
複雑なテストは実施していないがLAMP構成等単純な構成や簡易な作りのサーバを立てた際のテストには非常に便利そう
autoaddやaddコマンドで簡単にテストが作れる
現在の設定を元にテストケースの生成をしてくれるので構築しつつテストケース作成が容易
ファイルの中に含まれる文字列の検索やコマンドの結果も取れるのでちゃんと作れば複雑なこともできそう
exportを使用すれば一覧できるため内容確認が容易

Gossとは

YAMLから読み込みの出来るserverspec的なテストツール
こちらのリポジトリを参照

今回の環境

  • AmazonLinux
  • テスト用にhttpdを導入

導入

# curl -fsSL https://goss.rocks/install | sh
Downloading https://github.com/aelsabbahy/goss/releases/download/v0.3.1/goss-linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   589    0   589    0     0    977      0 --:--:-- --:--:-- --:--:--   978
100 7791k  100 7791k    0     0   711k      0  0:00:10  0:00:10 --:--:-- 1256k
Goss v0.3.1 has been installed to /usr/local/bin/goss
goss --version
goss version v0.3.1
Downloading https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/dgoss/dgoss
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2241  100  2241    0     0   7892      0 --:--:-- --:--:-- --:--:--  7918
dgoss master has been installed to /usr/local/bin/dgoss

# goss --version (-vでも可)
goss version v0.3.1

テストファイル作成

サンプルではsshdを使用しているが差分を見やすくするためにhttpdを使用

1. httpdが導入済み、停止中・自動起動なしの環境
# chkconfig httpd --list
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# service httpd status
httpd is stopped

# goss autoadd httpd
Adding Package to './goss.yaml':

httpd:
  installed: true
  versions:
  - 2.2.31

Adding Service to './goss.yaml':

httpd:
  enabled: false
  running: false

2. httpdが導入済み、起動中・自動起動有りの環境
# chkconfig httpd --list
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
# service httpd status
httpd (pid  2836) is running...

# goss autoadd httpd
Adding Package to './goss.yaml':

httpd:
  installed: true
  versions:
  - 2.2.31

Adding Process to './goss.yaml':

httpd:
  running: true

Adding Port to './goss.yaml':

tcp6:80:
  listening: true
  ip:
  - '::'

Adding Service to './goss.yaml':

httpd:
  enabled: true
  running: true

上記のように現在の状態が追加される
autoaddを使用すれば自動的に指定したリソースに合わせて色々とテストケースを出力してくれる
簡易的なものに関しては autoaddadd を使用してテストケースを作れる
使用可能なリソースタイプはドキュメントを参照
単一のテストケースを使用する場合は下記のように add を指定すれば良い
こちらも使用できるリソースタイプは決まっているので注意

# goss add service httpd
Adding Service to './goss.yaml':

httpd:
  enabled: false
  running: false

# goss add file /tmp/sample.txt
Adding File to './goss.yaml':

/tmp/sample.txt:
  exists: true
  mode: "0644"
  size: 0
  owner: root
  group: root
  filetype: file
  contains: []

# goss add command "ls /tmp"
Adding Command to './goss.yaml':

ls /tmp:
  exit-status: 0
  stdout:
  - sample.txt
  stderr: []
  timeout: 10000

使用例

# goss validate
....

Total Duration: 0.004s
Count: 4, Failed: 0, Skipped: 0

# goss -g ./goss-httpd.yaml validate
....

Total Duration: 0.036s
Count: 4, Failed: 0, Skipped: 0

ファイルの指定がない場合はデフォルトのgoss.yamlが読み込まれる
特定のファイルを使用したい場合は -g/--gossfile でファイルを指定する

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1