# Test plan

| Parameter             | Description                                                                                   | Type     | Default |
| --------------------- | --------------------------------------------------------------------------------------------- | -------- | ------- |
| type                  | 测试计划类型, 请填写 GITHUB                                                                   | string   | 空      |
| schedule              | `@daily`: daily run, `@weekly`: weekly run 或者 `空值`: 日常不调度                            | string   | 空      |
| tags                  | 标签，用于测试计划检索, 如果 tags 中包含 `release` 则发版测试时会调度                         | [string] | 空      |
| testbed               | [Testbed 定义](test_cluster.md#Testbed)                                                       | 结构体   | -       |
| waitTimeout           | pending 等待超时(以秒计，默认两个星期)                                                        | int      | 604800  |
| steps                 | 编排串行跑测试的结构                                                                          | 数组     | -       |
| steps[*].name         | 步骤名称, 由`字母`，`数字`， `-` 组成                                                         | string   | -       |
| steps[*].caseName     | 在 TCMS 中录入的测试用例名称                                                                  | string   | -       |
| steps[*].caseImage    | 覆盖用例镜像                                                                                  | string   | -       |
| steps[*].arguments    | 实例化的参数, 只允许覆盖 [字符串参数](case_mng.md#字符串类型参数)                             | -        |
| pipeline              | 编排可并行跑测试的 DAG 结构, 用于满足更灵活的编排需求                                         | 数组     | -       |
| pipeline[*].name      | 步骤名称, 由`字母`，`数字`， `-` 组成。要么所有的步骤名都为空（服务端自动生成），要么都不为空 | string   | -       |
| pipeline[*].caseName  | 在 TCMS 中录入的测试用例名称                                                                  | string   | -       |
| pipeline[*].caseImage | 覆盖用例镜像                                                                                  | string   | -       |
| pipeline[*].arguments | 实例化的参数, 只允许覆盖 [字符串参数](case_mng.md#字符串类型参数)                             | -        |
| pipeline[*].after     | 该步骤要等待其他步骤运行成功后                                                                | [string] | -       |
| failFast              | `failFast: false` 意味某个步骤失败不会阻塞后置的步骤执行                                      | bool     | false   |

## 编排示例

```yaml
steps:
    - caseName: lightning_import_70gb_shard_row_id
      arguments:
          - name: target
            value: "{{testbed.upstream}}"
          - name: lightning
            value: "{{testbed.lightning}}"
    - caseName: lightning_list_partition_1.5k_import_local_backend
      arguments:
          - name: target
            value: "{{testbed.upstream}}"
          - name: lightning
            value: "{{testbed.lightning}}"
    - caseName: br_list_partition_1.5k_backup_restore
      arguments:
          - name: src_tidb
            value: "{{testbed.upstream}}"
          - name: dst_tidb
            value: "{{testbed.downstream}}"
          - name: br
            value: "{{testbed.br}}"
          - name: mc
            value: "{{testbed.tools}}"
    - caseName: dumpling_list_partition_1.5k_tables
      arguments:
          - name: target
            value: "{{testbed.upstream}}"
          - name: dumpling
            value: "{{testbed.dumpling}}"
```

更多示例请参考： https://github.com/pingcap/test-plan

## 测试资源类型子资源（subresource）

test-infra 支持几类常用的测试资源类型子资源（subresource）通过字符串类型参数注入，对于只需要获取 TiDB 集群访问地址的用例能够在不引入 test-infra SDK 的情况下就运行起来。

| 资源类型       | 子资源名称      | 备注                                                            |
| -------------- | --------------- | --------------------------------------------------------------- |
| `TIDB_CLUSTER` | `tidb.dsn`      | tidb dsn 子资源, 如：`mysql://root:@tc-tidb.testbed-dlpw4:4000` |
| `TIDB_CLUSTER` | `tidb.host`     | tidb host 子资源, 如：`tc-tidb.testbed-dlpw4`                   |
| `TIDB_CLUSTER` | `tidb.port`     | tidb port 子资源, 如：`4000`                                    |
| `TIDB_CLUSTER` | `tidb.username` | tidb username 子资源, 如：`root`                                |
| `TIDB_CLUSTER` | `tidb.password` | tidb password 子资源, 如：`''`                                  |

例如一个 testbed 中有如下声明：

```yaml
testbed:
    generateName: test-infra-
    items:
        - name: tc
          type: TIDB_CLUSTER
          spec:
              pd: { replicas: 1, image: "{{meta.parameters.pd_image}}" }
              tikv: { replicas: 1, image: "{{meta.parameters.tikv_image}}" }
              tidb: { replicas: 1, image: "{{meta.parameters.tidb_image}}" }
```

则在编排中可以通过如下的方式注入到[字符串类型参数](case_mng.md#字符串类型参数)中：

> 带有 `testbed.items` 前缀的变量用于注入子资源

```yaml
- caseName: example_case
  arguments:
      - name: dsn
        value: "{{testbed.items.tc.tidb.dsn}}"
      - name: host
        value: "{{testbed.items.tc.tidb.host}}"
      - name: port
        value: "{{testbed.items.tc.tidb.port}}"
      - name: user
        value: "{{testbed.items.tc.tidb.username}}"
      - name: password
        value: "{{testbed.items.tc.tidb.password}}"
```
