diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..09eba4a --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ +## Purpose + +Brief description of the purpose of this change. + +## Solution + +High level overview of what was done. This is the roadmap for those who are going to CR. + +## Semantic Versioning (check one) + +- [ ] The following were changed in a non-backward compatible way and requires a major version bump: + - _[link to the breaking change in the diff]_ +- [ ] Something public was added or changed in backward compatible way, this requires a minor version bump +- [ ] No public changes nor new features (backwards-compatible refactor or bug fix), so this can be included in a patch + release + +## How to QA + +- [ ] run the following related examples: **(fill in)** +- [ ] Other necessary steps needed to fully exercise the solution should be added here. **(fill in)** diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4330d63 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + day: sunday + commit-message: + prefix: fix + prefix-development: chore + include: scope diff --git a/.gitignore b/.gitignore index 9ed3b07..b62b9b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.test +test-reports/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6b333f5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go -go: - - 1.7.5 - - 1.8 - - tip - -os: - - linux - - osx - -sudo: false - -install: - - echo "skipping travis' default" - -script: - - make test-all diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44eae26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +# This is a Golang library; it doesn't produce +# any artifacts. +FROM scratch diff --git a/Makefile b/Makefile index a717897..cc87cc3 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,11 @@ -PACKAGES = $(shell go list ./... | grep -v '/vendor/') +SHELL := /bin/bash -default: test +test: tools + rm -rf test-reports + mkdir test-reports + go clean -testcache + GO111MODULE="off" go test -v 2>&1 ./... | go-junit-report -iocopy -set-exit-code -out test-reports/unit-test-report.xml -test-all: vet lint test test-race - -test: - go test -v -parallel=4 ${PACKAGES} - -test-race: - go test -v -race ${PACKAGES} - -vet: - go vet ${PACKAGES} - -lint: - @go get github.com/golang/lint/golint - go list ./... | grep -v vendor | xargs -n1 golint - -cover: - @go get golang.org/x/tools/cmd/cover - go test -coverprofile=cover.out - go tool cover -html cover.out - rm cover.out - -.PHONY: test test-race vet lint cover +tools: + go install github.com/jstemmer/go-junit-report/v2@v2.0.0 + GO111MODULE="off" go get golang.org/x/crypto/ssh/terminal \ No newline at end of file diff --git a/aviary.yaml b/aviary.yaml new file mode 100644 index 0000000..b825518 --- /dev/null +++ b/aviary.yaml @@ -0,0 +1 @@ +version: 1 diff --git a/read.go b/read.go index 66825f4..1da8720 100644 --- a/read.go +++ b/read.go @@ -46,9 +46,9 @@ func (i *UI) read(opts *readOptions) (string, error) { resultErr = fmt.Errorf("failed to read the input: %s", err) } - resultStr = strings.TrimSuffix(line, LineSep) + resultStr = strings.Trim(line, LineSep) // brute force for the moment - resultStr = strings.TrimSuffix(line, "\n") + resultStr = strings.TrimSuffix(resultStr, "\n") } }() diff --git a/read_test.go b/read_test.go index 11cfbe2..c04f5e9 100644 --- a/read_test.go +++ b/read_test.go @@ -2,12 +2,18 @@ package input import ( "bytes" + "fmt" "io" "io/ioutil" "testing" ) func TestRead(t *testing.T) { + var stringWithSpace = fmt.Sprintf("taichi nakashima%s", LineSep) + var expectedWithSpace = "taichi nakashima" + var stringNoSpace = fmt.Sprintf("passw0rd%s", LineSep) + var expectedNoSpace = "passw0rd" + cases := []struct { opts *readOptions userInput io.Reader @@ -18,8 +24,8 @@ func TestRead(t *testing.T) { mask: false, maskVal: "", }, - userInput: bytes.NewBufferString("passw0rd"), - expect: "passw0rd", + userInput: bytes.NewBufferString(stringNoSpace), + expect: expectedNoSpace, }, { @@ -27,8 +33,8 @@ func TestRead(t *testing.T) { mask: false, maskVal: "", }, - userInput: bytes.NewBufferString("taichi nakashima"), - expect: "taichi nakashima", + userInput: bytes.NewBufferString(stringWithSpace), + expect: expectedWithSpace, }, // No good way to test masking... diff --git a/skynet.yaml b/skynet.yaml new file mode 100644 index 0000000..d559f98 --- /dev/null +++ b/skynet.yaml @@ -0,0 +1,22 @@ +# Testing with Skynet - https://github.com/Workiva/skynet/tree/master/docs +name: unit-tests +image: golang:1.18-bullseye +description: run unit tests +size: small +timeout: 600 # 10 minutes +contact: support-onecloud + +run: + on-pull-request: true + on-tag: true + when-branch-name-is: + - master + +scripts: + - make test + +artifacts: + - test-reports + +test-reports: + - test-reports