# 快速开始

1 分钟跑起 go-tpc 测试。

<details>
因为资源申请较慢，实际时间大于 1 分钟 }:-|
</details>

## 一、安装命令行工具 tcctl

```bash
curl http://fileserver.pingcap.net/download/pingcap/qa/test-infra/tcctl-install.sh | bash
```

## 二、申请 token

1. 打开 <https://tcms.pingcap.net/dashboard/settings/tokens> -> 点击 `Generate new token`
2. 将生成的 token 持久化到本地：

```bash
tcctl config --token $(YOUR_TOKEN) --rms-host 'http://rms-staging.pingcap.net:30007'
```

<details>
test-infra 有两套用例运行环境（staging & prod）, 在用例 daily run 之前，我们通常只会和 staging 环境打交道，所以用参数 `--rms-host` 将 staging 环境地址持久化到了本地。
</details>

## 三、运行测试

我们跑一个简单的 go-tpc 测试：

```bash
echo 'apiVersion: api/v1
kind: Plan
name: my-test
testbed:
  generateName: my-test-testbed-
  resourcePool: ksyun-default
  reclaimPolicy:
    gcStrategy:
      onCompletion:
        reserveEnv:
          durationOnWorkingHour: 1h
  items:
    - name: tc
      type: TIDB_CLUSTER
      spec:
        imagePullPolicy: IfNotPresent
        version: master
        pd:
          replicas: 1
          baseImage: hub-new.pingcap.net/qa/pd
        tikv:
          replicas: 1
          baseImage: hub-new.pingcap.net/qa/tikv
        tidb:
          replicas: 1
          baseImage: hub-new.pingcap.net/qa/tidb
    - name: go-tpc-workload
      type: WORKLOAD_NODE
      spec:
        container:
          name: go-tpc
          image: "hub.pingcap.net/qa/go-tpc:v1.0.7"
          command:
            - tail
            - "-f"
            - /dev/null
          resources:
            requests:
              memory: 64Mi
              cpu: 1000m
cases:
  - name: myTPCC
    framework:
      generic:
        command: ["/bin/example", "--dsn={{parameters.dsn}}"]
        image: hub.pingcap.net/qa/example_workload_node
    parameters:
      - name: tc
        type: RESOURCE
      - name: go-tpc-workload
        type: RESOURCE
      - name: dsn
        # type: STRING # <-- type 默认为 STRING
steps:
  - caseName: myTPCC
    arguments:
      - name: tc
        value: "{{testbed.tc}}"
      - name: go-tpc-workload
        value: "{{testbed.go-tpc-workload}}"
      - name: dsn
        value: "{{testbed.items.tc.tidb.dsn}}"
' | tcctl run -f -
```

这段命令会输出一个链接，我们可以通过这个链接查看测试结果：![oneshot-url](static/oneshot-url.jpg)
如 <https://tcms.pingcap.net/dashboard/executions/plan/514160>。
同时可以用 `tcctl testbed get -p 514160` 生成 kubeconfig.yaml 连上测试环境。
