Skip to content

Instantly share code, notes, and snippets.

@morika-t
Last active December 31, 2015 19:29
Show Gist options
  • Save morika-t/8034127 to your computer and use it in GitHub Desktop.
Save morika-t/8034127 to your computer and use it in GitHub Desktop.
Cloud Foundry Advent Calendar 2013 12月20日(金) cf-acceptance-testsを使ってみる

cf-acceptance-testsを使ってみる

CATとは

  • google groupsの投稿によると「New integration tests for CF」用のツール
  • BOSHのテストのBATのようにCATと略すらしい
  • go実装のcfコマンドgcfとcurlを使う
  • goのBDD風なテストのフレームワークの「Ginkgo」利用している

参考URL: https://groups.google.com/a/cloudfoundry.org/forum/#!topic/vcap-dev/2daJJklWTOY

Ginkgo

事前に必要なもの

  • gcfのPATHが通っている事
    • export PATH=$GCF_PATH:$PATH
  • curlのPATHが通っている事
  • go環境(今回はgvmを使って1.2)を構築した環境で実施
  • gcfでログインできるCF環境(事前にpush出来るような状況にしておくと良い?)

動かし方

ソースのクローン

$ mkdir -p pce/src/github.com/pivotal-cf-experimental
$ cd pce/src/github.com/pivotal-cf-experimental
$ git clone https://github.com/pivotal-cf-experimental/cf-acceptance-tests.git
$ cd cf-acceptance-tests/

関連ファイルの取得

$ export GOPATH=~/pce
$ cd $GOPATH
$ go get ./...

設定ファイルの作成

$ cd src/github.com/pivotal-cf-experimental/cf-acceptance-tests/
$ vi integration_config.json

integration_config.json

apps_domainはテスト実施するcfのドメイン

{ "apps_domain": "192.168.12.129.xip.io" }

設定ファイルの読み込み用設定

$ export CONFIG=$PWD/integration_config.json

テスト実行

$ ./bin/test -nodes=1

---途中のログ---

=== RUN TestLifecycle

Running Suite: Application Lifecycle
====================================
Random Seed: 1387163583
Will run 16 of 17 specs

テスト出力を細かく表示する場合は、以下を実行すると細かく出る
export CF_VERBOSE_OUTPUT=true

利用可能なオプション

-nodes部分はginkgoのオプションですので以下の様なオプションが存在しています

Usage of ginkgo:

ginkgo
  Run the tests in the current directory.  The following flags are available:
  -cover=false: Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory
  -failOnPending=false: If set, ginkgo will mark the test suite as failed if any specs are pending.
  -focus="": If set, ginkgo will only run specs that match this regular expression.
  -i=false: Run go test -i first, then run the test suite
  -noColor=false: If set, suppress color output in default reporter.
  -nodes=1: The number of parallel test nodes to run
  -noisyPendings=true: If set, default reporter will shout about pending tests.
  -r=false: Find and run test suites under the current directory recursively
  -race=false: Run tests with race detection enabled
  -randomizeAllSpecs=false: If set, ginkgo will randomize all specs together.  By default, ginkgo only randomizes the top level Describe/Context groups.
  -seed=1387165165: The seed used to randomize the spec suite.
  -skip="": If set, ginkgo will only run specs that do not match this regular expression.
  -skipMeasurements=false: If set, ginkgo will skip any measurement specs.
  -slowSpecThreshold=5: (in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter (default: 5 seconds).
  -v=false: If set, default reporter print out all specs as they begin.

検証に使われるアプリ

Dora the Explorer

https://github.com/pivotal-cf-experimental/cf-acceptance-tests/tree/master/assets/dora

Endpoints
GET / Hello Dora
GET /id The id of the instance
POST /session Sets up the cookies for a sticky session
POST /stress_tester?cpu=1&io=1 Starts the stress tester with 1 cpu and 1 io process
GET /stress_tester Gets all the stress testers processes
DELETE /stress_tester Kill all the stress testers processes
GET /find/:filename Finds a file in your instance
GET /sigterm Displays all possible sigterms
GET /delay/:seconds Waits for n seconds
GET /sigterm/:signal Sends the specfied signal
GET /logspew/:bytes Spews out n bytes to the logs
GET /echo/:destination/:output Echos out the output to the destination
GET /env/:name Prints out the env variable

hello-world

https://github.com/pivotal-cf-experimental/cf-acceptance-tests/tree/master/assets/hello-world

ただのhello worldを表示するrackアプリケーション

各ファイルのテスト内容把握

admin_buildpack_lifecycle_test.go

概要

  • before eachで検証用アプリに対応したbiuldpackをgcf create-buildpackで作成
  • after eachでgcf delete-buildpackで「OK」が返る事
  • buildpackの特定が出来るパターン
    • gcf push アプリ名 -pでpushした際に以下が表示される事
      • 「Staging with Simple Buildpack」
      • 「App started」
  • buildpack特定が出来ないパターン
    • os.Removeでbuildpack特定用のファイルを削除する
    • gcf pushすると「Staging error」が返る事
  • buildpackを削除したパターン
    • gcf delete-buildpackで「OK」が返る事
    • gcf pushを実行すると「Staging error」が返る事
  • buildpackが無効のパターン
    • /v2/buildpacks?q=name:でbuildpackのguidを取得し
    • ApiRequestでenabled:falseに設定
    • gcf pushを実行すると「Staging error」となる事

changing_start_command_test.go

概要

  • before eachでgcf pushで以下を指定した際に「App started」が返る事
    • -p doraPath指定
    • -d configのドメイン
    • -c 起動用のコマンド「FOO=foo bundle exec rackup config.ru -p $PORT」
  • after eachでアプリを削除した際に「OK」が返る事
  • curlで/env/FOOにアクセスすると「foo」が返る事
  • /v2/apps?q=nameにアクセスしguidを取得
  • ApiRequestでFOO=の部分をbarに変えた状態でPUTする
  • gcf stopアプリ名でアプリを停止させた際に「OK」が返る事
  • curlで/env/FOOにアクセスすると「404」が返る事
  • gcf startアプリ名でアプリを起動させると「App started」が返る事
  • curlで/env/FOOにアクセスすると先ほど書き換えた値の「bar」が返る事

dynamic_info_test.go

概要

  • アプリ名はランダムな名称でbeforeeachでアプリをpushし「App started」が返る事
  • after eachでアプリを削除した際に「OK」が返る事
  • filesの検証
    • gcf files アプリ名でアクセスした際に「app/」が返ってくる事
    • gcf files アプリ名 app/でアクセスした際に「config.ru」が返ってくること
    • gcf files アプリ名 app/config.ruでアクセスした際に「run Dora」と返る事
  • crashイベントの検証
    • curlで/sigterm/KILLにアクセスし「ExitWith(0)」となること
    • gcf events アプリ名でアクセスした際に「exited」が返る事
  • scaleコマンドの検証
    • gcf scale アプリ名 -i 2とアクセスした際に「OK」が返る事
    • gcf app アプリ名とアクセスした際に「#0」と「#1」の2インスタンス分が表示される事

init_test.go

概要

  • configの読み込み
  • AppNameの初期化
    * 2種類の検証用アプリのpath指定
    • doraPath
    • helloPath
  • AppUriの規則設定
    • http://アプリ名+configに入れたドメイン+stringで渡ってくる文字(例:/など)
  • curlingでcurlでアクセスする宣言

lifecycle_test.go

概要

  • アプリ名はランダムな名称でbeforeeachでアプリをpushし「App started」が返る事
  • after eachでアプリを削除した際に「OK」が返る事
  • pushの検証
    • curlで/にアクセスして「Hi, I’m Dora!」の文字が返る事
  • stopの検証
    • gcfでstopを実行し「OK」が返る事
    • curlで5秒タイムアウト?で/にアクセスして「404」が返る事
    • 再度アプリをgcfでstartさせた際に「App started」が返る事
    • curlで/にアクセスすると「Hi, I’m Dora!」が返る事
  • updateの検証
    • まずcurlで/にアクセスすると「Hi, I’m Dora!」が返る事
    • 次に同じアプリ名で別のアプリをgcfでpushすると「App started」が返る事
    • curlでアクセスすると更新後のアプリの応答「Hello, world!」が返る事
  • deleteの検証
    • gcfでアプリを削除した際に「OK」が返る事
    • gcf appで削除したアプリ名でアクセスすると「not found」が返る事
    • curlで削除したアプリの/にアクセスすると「404」が返る事

one_push_many_restarts_test.go

概要

  • curlを使って/にアクセスして「Hi, I’m Dora!」の文字が返る事
  • gcfでアプリを停止した際にコマンドの応答で「OK」が返る事
  • curlを使って/にアクセスした際に停止している為「404」が返る事
  • gcfでアプリを起動した際にコマンドの応答で「App started」が返る事
  • curlを使って/にアクセスした際に「Hi, I’m Dora!」の文字が返る事

output_volume_test.go

概要

  • アプリ名はランダムな名称でbeforeeachでアプリをpushし「App started」が返る事
  • after eachでアプリを削除した際に「OK」が返る事
  • curlで/idにアクセスしアプリのidを取得する
  • アプリにアクセスすると特定の容量でログを吐けるようになっているので
    • curlで/logspew/3354432にアクセスすると「Just wrote 33554432 random bytes to the log」が返る事
  • 10秒スリープ後curlで/idにアクセスし、ログを吐く前のidと比較し同一である事
  • curlで/logspew/2にアクセスすると「Just wrote 2 random bytes to the log」が返る事

staging_log_test.go

概要

  • gcfでpushした際にstagingの以下のメッセージが出力される事
    • Installing dependencies
    • Uploading droplet
    • App started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment