doc.dev1x.org

runnによるシナリオテスト

Appendix-1 サンプルコード

scenario_test.go

//go:build scenariotest

package scenario_test

import (
    "context"
    "testing"

    "github.com/k1LoW/runn"
)

func Test_ScenarioTest(t *testing.T) {

    runner, err := runn.Load(
        "./test.yaml",
        runn.T(t),
        runn.Runner("req", "http://localhost:8080"),
        runn.Runner("db", "xxxxxx"),
    )
    if err != nil {
        t.Fatal(err)
    }

    ctx := context.TODO()
    if err := runner.RunN(ctx); err != nil {
        t.Fatal(err)
    }

}

test.yaml

desc: "プロジェクト一覧を取得"
debug: true
runners:
  db:
    dsn: xxxxxx
steps:
  step01:
    req:
      /project:
        get:
          body: null
    test: steps.step01.res.status == 200
  step02:
    test: len(steps.step01.res.body.project) == 2
  step03:
    db:
      query: "SELECT * FROM project;"
    test: len(steps.step03.rows) > 1