0
0

More than 1 year has passed since last update.

【DevContainers】Featuresをテストする方法

Posted at

テスト方法

以下のようにtestディレクトリを作成する。
testディレクトリ内のディレクトリ名はテストするFeatureと対応していなければならない。

$ tree
.
├── src
│   ├── git
│   │   ├── devcontainer-feature.json
│   │   └── install.sh
...
├── test
│   ├── _global
│   │ ├── scenarios.json
│   │ └── some_test_scenario.sh
│   ├── git
│   │   ├── scenarios.json
│   │   ├── install_dotnet_and_oryx.sh
│   │   └── test.sh 
...

test/git/test.shを以下のように作成する。

#!/bin/bash

set -e

source dev-container-features-test-lib

check "version" git --version

reportResults
  • check <LABEL> <cmd> [arg...]...
    <cmd>を実行し終了コードに応じて成功/失敗を表示する。

  • reportResults
    checkcheckMultipleの結果を出力する。

テストを実行するにはDevContainersCLIを使用する。

devcontainer features test --features Feature名 --base-image ベースイメージ .
devcontainer features test --features git --base-image mcr.microsoft.com/devcontainers/base:debian .

上記の場合にはgitFeatureをdebianのベースイメージを使用してテストする。

以下のようにコマンドを短くできる。

devcontainer features test -f git -b debian

シナリオ

オプションを指定してテストを実行するにはscenarios.jsonとそれに対応するファイルを作成する。

  • scenarios.json
{
  "git-scenario": {
      "image": "ubuntu:focal",
      "features": {
          "git": {
            "version": "2.20.1"
          }
      }
  }
}
  • git-scenario.sh
#!/bin/bash

set -e

source dev-container-features-test-lib

check "version" git --version

reportResults

scenarios.json"git-scenario"には.shのファイル名を記述する。"git"にはFeature名を記述する。

例ではgitFeatureをgit-scenario.shの内容でテストすることになる。

なおscenarios.jsonに対応するファイルが存在しない場合にはテスト実行時に以下のようなエラーが出る。

$ devcontainer features test --features git-from-src-fast --base-image mcr.microsoft.com/devcontainers/base:debian .

...

[-] No scenario test script found at path '/workspaces/devcontainers-features/test/git-from-src-fast/git-from-src-fast.sh'.
  Either add a script to the test folder, or remove from scenarios.json.
0
0
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
0
0