mumoshu / variant2

Turn your bash scripts into a modern, single-executable CLI app today
MIT License
141 stars 11 forks source link

Improve readability of test output #20

Open johncblandii opened 4 years ago

johncblandii commented 4 years ago
➜ variant test
terraform init
terraform plan -out=acme.planfile
aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm
case "ok": assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
, where run.res.stdout=aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm (string) case.out=aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm (string)aws --profile company-blah-helm eks update-kubeconfig --name=company-blah-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah-helm
case "ok2": assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
, where run.res.stdout=aws --profile company-blah-helm eks update-kubeconfig --name=company-blah-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah-helm (string) case.out=aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm (string)--- FAIL: aws_eks_kubeconfig (0.01s)
    --- FAIL: aws_eks_kubeconfig/ok (0.01s)
        app.go:1040: case "ok": assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
            , where run.res.stdout=aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm (string) case.out=aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm (string)
    --- FAIL: aws_eks_kubeconfig/ok2 (0.00s)
        app.go:1040: case "ok2": assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
            , where run.res.stdout=aws --profile company-blah-helm eks update-kubeconfig --name=company-blah-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah-helm (string) case.out=aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm (string)
FAIL
Error: test exited with code 1

Note: the failure here is fine. I was refactoring.

This output is not very readable.

Potential output without errors:

➜ variant test
PASS terraform-core_test.variant
  ✓  case "init" (0.01s): terraform init
  ✓  case "plan" (0.01s): terraform plan -out=acme.planfile

PASS aws_test.variant
  ✓  case "ok" (0.01s): aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm
  ✓  case "ok2" (0.01s): aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm

Potential output with errors:

➜ variant test
PASS terraform-core_test.variant
  ✓  case "init" (0.01s): terraform init
  ✓  case "plan" (0.01s): terraform plan -out=acme.planfile

FAIL aws_test.variant

  ✕  case "ok" (0.01s): aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm

  assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
  run.res.stdout
    (string) aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm
  case.out
    (string) aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm

  ✕  case "ok2" (0.01s): aws --profile company-blah-helm eks update-kubeconfig --name=company-blah-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah-helm

  assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
  run.res.stdout
    (string) aws --profile company-blah2-helm eks update-kubeconfig --name=company-blah2-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah2-helm (string) case.out=aws --profile company-acme-helm eks update-kubeconfig --name=company-acme-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.acme-helm
  case.out
    (string) aws --profile company-blah-helm eks update-kubeconfig --name=company-blah-eks-cluster --region=us-east-2 --kubeconfig=/path/to/kube/kubecfg.blah-helm

Error: test exited with code 1

Note: this one is still pretty verbose and could likely be cleaned up a bit, but it is readable.