Skip to content

Commit

Permalink
Convert integration tests to use TestScript
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfetch committed Dec 30, 2022
1 parent 1e8e1e0 commit 5b31a62
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 121 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ require (

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
Expand Down
121 changes: 0 additions & 121 deletions jkl_integration_test.go

This file was deleted.

27 changes: 27 additions & 0 deletions script_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build integration

package jkl_test

// Note: Use go test -testwork to preserve the TestScript temporary directory.

import (
"os"
"testing"

"github.com/ivanfetch/jkl"
"github.com/rogpeppe/go-internal/testscript"
)

func init() {
// Enable debugging for all tests, via the same environment variable the jkl
// binary uses.
if os.Getenv("JKL_DEBUG") != "" {
jkl.EnableDebugOutput()
}
}

func TestScript(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata/script",
})
}
8 changes: 8 additions & 0 deletions testdata/script/install_github-cli.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mkdir $WORK/home/testuser
env HOME=$WORK/home/testuser
env PATH=$HOME/.jkl/bin:$PATH
exec jkl install github:cli/cli:2.14.2
! stdout .
! stderr .
exec gh version
stdout 'gh version 2.14.2'
8 changes: 8 additions & 0 deletions testdata/script/install_kind.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mkdir $WORK/home/testuser
env HOME=$WORK/home/testuser
env PATH=$HOME/.jkl/bin:$PATH
exec jkl install github:kubernetes-sigs/kind:0.14.0
! stdout .
! stderr .
exec kind version
stdout 'kind v0.14.0'
19 changes: 19 additions & 0 deletions testdata/script/install_prme.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mkdir $WORK/home/testuser
env HOME=$WORK/home/testuser
env PATH=$HOME/.jkl/bin:$PATH
exec jkl install github:ivanfetch/prme:0.0.4
! stdout .
! stderr .
# prme -version exits with value 1
! exec prme -version
! stdout .
# A prme bug does not present the version correctly
stderr 'prme version ,'
# Install the latest prme
exec jkl install github:ivanfetch/prme
! stdout .
! stderr .
env JKL_PRME=latest
! exec prme -version
! stdout .
stderr 'prme version v0.0.6'
19 changes: 19 additions & 0 deletions testdata/script/install_terraform.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mkdir $WORK/home/testuser
env HOME=$WORK/home/testuser
env PATH=$HOME/.jkl/bin:$PATH
exec jkl install hashi:terraform:1.0.0
! stdout .
! stderr .
exec terraform version
stdout 'Terraform v1.0.0'
# This version requires jkl to fetch jultiple pages of Hashicorp releases
exec jkl install hashicorp:terraform:0.11.15
! stdout .
! stderr .
env JKL_TERRAFORM=0.11.15
exec terraform version
stdout 'Terraform v0.11.15'
# This version does not exist
! exec jkl install hashicorp:terraform:10.2
! stdout .
stderr 'Error: no version found to match "10.2"'
5 changes: 5 additions & 0 deletions testdata/script/install_without_jkl_bin_n_path.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mkdir $WORK/home/testuser
env HOME=$WORK/home/testuser
exec jkl install hashi:terraform:1.0.0
stdout 'WARNING: Please add the directory'
stdout 'to your PATH environment variable'
3 changes: 3 additions & 0 deletions testdata/script/version.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec jkl version
stdout 'jkl version'
stdout 'git commit '

0 comments on commit 5b31a62

Please sign in to comment.