Skip to content

Commit

Permalink
Merge pull request #9 from little-angry-clouds/fix/tty_support_for_wr…
Browse files Browse the repository at this point in the history
…appers
  • Loading branch information
alexppg authored Jun 18, 2020
2 parents df76b0f + bdeb5a8 commit 3a57d11
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
submodules: recursive
- name: Run unit tests
run: make unit-test
- uses: engineerd/[email protected]
- name: Run int tests
run: sudo add-apt-repository ppa:duggan/bats && sudo apt-get update && sudo apt-get install bats -y && make int-test
- name: Run static checks
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Create base for installin binaries
# Create base for installing binaries
BIN = $(CURDIR)/bin
$(BIN):
@mkdir -p $@
$(BIN)/golangci-lint: | $(BIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.24.0
$(BIN)/gopherbadger: | $(BIN)
GOBIN=$(BIN) go get github.com/jpoles1/gopherbadger
$(BIN)/kind: | $(BIN)
curl -Lo $(BIN)/kind https://kind.sigs.k8s.io/dl/v0.8.1/kind-$$(uname)-amd64; \
chmod +x $(BIN)/kind

# Binaries to install
GOLANGCI-LINT = $(BIN)/golangci-lint
GOPHERBADGER = $(BIN)/gopherbadger
KIND = $(BIN)/kind

###############################################################################
###############################################################################
Expand All @@ -35,7 +39,7 @@ static: | $(GOLANGCI-LINT) $(GOPHERBADGER)
unit-test:
go test ./...

int-test:
int-test: | $(KIND)
bats tests/test

PLATFORMS := linux-amd64 linux-386 darwin-amd64 darwin-386 windows-amd64 windows-386
Expand Down
14 changes: 5 additions & 9 deletions internal/wrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"syscall"

"github.com/mitchellh/go-homedir"
)
Expand Down Expand Up @@ -34,15 +34,11 @@ func Wrapper(binName string) {
}

finalVersion = strings.Trim(string(rawVersion), "\n")

cmd := exec.Command(fmt.Sprintf("%s-v%s", binName, finalVersion), os.Args[1:]...) // nolint: gosec
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
bin := fmt.Sprintf("%s/%s-v%s", binPath, binName, finalVersion)
args := append([]string{bin}, os.Args[1:]...)
err = syscall.Exec(bin, args, os.Environ()) // golint: nosec

if err != nil {
if strings.Contains(err.Error(), "executable file not found in $PATH") {
fmt.Printf("%s\n", err)
}
fmt.Printf("%s\n", err)
}
}
36 changes: 34 additions & 2 deletions tests/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ load "lib/bats-support/load"
load "lib/bats-assert/load"

function setup() {
if [[ ! -e ./bin/kbenv ]]
if [[ ! -e ./bin/kbenv ]]
then
make build
elif [[ ! -e ./bin/helmenv ]]
then
make build
elif [[ ! -e ./bin/kubectl-wrapper ]]
then
make build
elif [[ ! -e ./bin/helm-wrapper ]]
then
make build
fi
Expand Down Expand Up @@ -61,6 +70,29 @@ function setup() {
assert_output --partial 'GitVersion:"v1.18.1"'
run ./bin/helm-wrapper version --client
assert_output --partial 'Version:"v3.2.0"'
run ./bin/kbenv uninstall 1.18.2
run ./bin/kbenv uninstall 1.18.1
run ./bin/helmenv uninstall 3.2.0
}

@test "apply" {
if [[ "$KIND_CREATE_CLUSTER" == "true" ]]
then
export PATH=$(pwd)/bin:$PATH
teardownCallback=$(create_cluster)
fi

run ./bin/kbenv install 1.18.1
run ./bin/kubectl-wrapper create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
assert_success
pod=$(./bin/kubectl-wrapper get pod -l app=hello-node -o=custom-columns=:.metadata.name | tail -n1)
run ./bin/kubectl-wrapper rollout status deploy hello-node
run ./bin/kubectl-wrapper exec "$pod" -- ls
assert_success
refute_output --partial "Unable to use a TTY"
run ./bin/kbenv uninstall 1.18.1

if [[ "$KIND_CREATE_CLUSTER" == "true" ]]
then
eval "$teardownCallback"
fi
}

0 comments on commit 3a57d11

Please sign in to comment.