-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for all subcommand #42
Conversation
Codecov Report
@@ Coverage Diff @@
## main #42 +/- ##
===========================================
+ Coverage 47.31% 84.40% +37.09%
===========================================
Files 10 10
Lines 279 295 +16
===========================================
+ Hits 132 249 +117
+ Misses 145 33 -112
- Partials 2 13 +11
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I don't know why the CI passed, but this commit b515c5a seems to fail on local testing. $ sw_vers
ProductName: macOS
ProductVersion: 12.5
BuildVersion: 21G72
$ go version
go version go1.19.1 darwin/amd64
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
$ git show
commit b515c5abdf5385ee3ad23ceabe44d1aa50bc6347 (HEAD -> main, upstream/main, upstream/HEAD, origin/main, origin/HEAD)
Merge: d25b452 514386f
Author: CHIKAMATSU Naohiro <[email protected]>
Date: Sat Sep 17 16:00:07 2022 +0900
Merge pull request #42 from nao1215/add-unit-tests-for-subcmd
Add unit test for all subcommand Logs$ go test ./...
? github.com/nao1215/gup [no test files]
gup:WARN : can't get 'test'package path information. old go version binary
--- FAIL: Test_export (0.02s)
--- FAIL: Test_export/can_not_make_.config_directory (0.00s)
export_test.go:196: value is mismatch (-want +got):
[]string{
strings.Join({
"gup:ERROR: can not make config directory: mkdir /.config: ",
- "permission denied",
+ "read-only file system",
}, ""),
"",
}
gup:ERROR: /.config/gup/gup.conf is not found
gup:ERROR: can not parse command line argument: flag accessed but not defined: dry-run
gup:ERROR: testdata/empty_conf/.config/gup/gup.conf is not found
gup:ERROR: testdata/can_not_read_conf/.config/gup/gup.conf is not found
gup:ERROR: no such file or directory: testdata/delete/posixer.exe
gup:CHECK: remove testdata/delete/posixer? [Y/n] gup:INFO : removed testdata/delete/posixer
gup:CHECK: remove testdata/delete/posixer? [Y/n] gup:INFO : cancel removal testdata/delete/posixer
gup command update binaries installed by 'go install'.
If you update all binaries, just run '$ gup update'
Usage:
gup [command]
Available Commands:
check Check the latest version of the binary installed by 'go install'
export Export the binary names under $GOPATH/bin and their path info. to gup.conf.
help Help about any command
import Install command according to gup.conf.
list List up command name with package path and version under $GOPATH/bin or $GOBIN
remove Remove the binary under $GOPATH/bin or $GOBIN
update Update binaries installed by 'go install'
version Show gup command version information
Flags:
-h, --help help for gup
Use "gup [command] --help" for more information about a command.
Error: unknown flag: --no-exist-option
Usage:
gup [command]
Available Commands:
check Check the latest version of the binary installed by 'go install'
export Export the binary names under $GOPATH/bin and their path info. to gup.conf.
help Help about any command
import Install command according to gup.conf.
list List up command name with package path and version under $GOPATH/bin or $GOBIN
remove Remove the binary under $GOPATH/bin or $GOBIN
update Update binaries installed by 'go install'
version Show gup command version information
Flags:
-h, --help help for gup
Use "gup [command] --help" for more information about a command.
gup:ERROR: unknown flag: --no-exist-option
gup:INFO : removed testdata/delete/posixer
gup:INFO : Export /Users/admin/.config/gup/gup.conf
gup:INFO : create bash-completion file: testdata/.bash_completion
gup:INFO : create fish-completion file: testdata/.config/fish/completions/gup.fish
gup:INFO : create zsh-completion file: testdata/.zsh/completion/_gup
gup:ERROR: testdata/.config/gup/gup.conf is not found
--- FAIL: TestExecute_Update (0.00s)
root_test.go:476: rename /Users/admin/go/bin /Users/admin/go/bin.backup: file exists
--- FAIL: TestExecute_Update_DryRun (0.00s)
root_test.go:569: rename /Users/admin/go/bin /Users/admin/go/bin.backup: file exists
gup:WARN : not found 'test4' package in $GOPATH/bin or $GOBIN
FAIL
FAIL github.com/nao1215/gup/cmd 1.001s
? github.com/nao1215/gup/internal/assets [no test files]
? github.com/nao1215/gup/internal/cmdinfo [no test files]
? github.com/nao1215/gup/internal/completion [no test files]
? github.com/nao1215/gup/internal/config [no test files]
? github.com/nao1215/gup/internal/file [no test files]
? github.com/nao1215/gup/internal/goutil [no test files]
? github.com/nao1215/gup/internal/notify [no test files]
ok github.com/nao1215/gup/internal/print (cached)
ok github.com/nao1215/gup/internal/slice (cached)
FAIL To reproduceIf you have Docker installed, here's the Dockerfile to reproduce. FROM golang:1.18
WORKDIR /go/src
RUN \
git clone https://github.com/nao1215/gup.git && \
cd gup && \
go mod download && \
go test ./...
Logs$ docker build -t test:local .
[+] Building 17.1s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.18 0.0s
=> [1/3] FROM docker.io/library/golang:1.18 0.0s
=> CACHED [2/3] WORKDIR /go/src 0.0s
=> ERROR [3/3] RUN git clone https://github.com/nao1215/gup.git && cd gup && go mod download && go test ./... 17.0s
------
> [3/3] RUN git clone https://github.com/nao1215/gup.git && cd gup && go mod download && go test ./...:
#6 0.233 Cloning into 'gup'...
#6 13.94 ? github.com/nao1215/gup [no test files]
#6 16.77
#6 16.77 gup:WARN : can't get 'test'package path information. old go version binary
#6 16.77 --- FAIL: Test_export (0.03s)
#6 16.77 --- FAIL: Test_export/can_not_make_.config_directory (0.00s)
#6 16.77 export_test.go:196: value is mismatch (-want +got):
#6 16.77 []string{
#6 16.77 strings.Join({
#6 16.77 "gup:ERROR: ",
#6 16.77 - "can not make config directory: mkdir /.config: permission denied",
#6 16.77 + "no package information",
#6 16.77 }, ""),
#6 16.77 "",
#6 16.77 }
#6 16.77 gup:ERROR: /.config/gup/gup.conf is not found
#6 16.77 gup:ERROR: can not parse command line argument: flag accessed but not defined: dry-run
#6 16.77 gup:ERROR: testdata/empty_conf/.config/gup/gup.conf is not found
#6 16.77 gup:ERROR: testdata/can_not_read_conf/.config/gup/gup.conf is not found
#6 16.77 gup:ERROR: no such file or directory: testdata/delete/posixer.exe
#6 16.77 gup:CHECK: remove testdata/delete/posixer? [Y/n] gup:INFO : removed testdata/delete/posixer
#6 16.77 gup:CHECK: remove testdata/delete/posixer? [Y/n] gup:INFO : cancel removal testdata/delete/posixer
#6 16.77 gup:INFO : create bash-completion file: /root/.bash_completion
#6 16.77 gup:INFO : create fish-completion file: /root/.config/fish/completions/gup.fish
#6 16.77 gup:INFO : create zsh-completion file: /root/.zsh/completion/_gup
#6 16.77 gup command update binaries installed by 'go install'.
#6 16.77 If you update all binaries, just run '$ gup update'
#6 16.77
#6 16.77 Usage:
#6 16.77 gup [command]
#6 16.77
#6 16.77 Available Commands:
#6 16.77 check Check the latest version of the binary installed by 'go install'
#6 16.77 export Export the binary names under $GOPATH/bin and their path info. to gup.conf.
#6 16.77 help Help about any command
#6 16.77 import Install command according to gup.conf.
#6 16.77 list List up command name with package path and version under $GOPATH/bin or $GOBIN
#6 16.77 remove Remove the binary under $GOPATH/bin or $GOBIN
#6 16.77 update Update binaries installed by 'go install'
#6 16.77 version Show gup command version information
#6 16.77
#6 16.77 Flags:
#6 16.77 -h, --help help for gup
#6 16.77
#6 16.77 Use "gup [command] --help" for more information about a command.
#6 16.77 gup:INFO : append bash-completion: /root/.bash_completion
#6 16.77 Error: unknown flag: --no-exist-option
#6 16.77 Usage:
#6 16.77 gup [command]
#6 16.77
#6 16.77 Available Commands:
#6 16.77 check Check the latest version of the binary installed by 'go install'
#6 16.77 export Export the binary names under $GOPATH/bin and their path info. to gup.conf.
#6 16.77 help Help about any command
#6 16.77 import Install command according to gup.conf.
#6 16.77 list List up command name with package path and version under $GOPATH/bin or $GOBIN
#6 16.77 remove Remove the binary under $GOPATH/bin or $GOBIN
#6 16.77 update Update binaries installed by 'go install'
#6 16.77 version Show gup command version information
#6 16.77
#6 16.77 Flags:
#6 16.77 -h, --help help for gup
#6 16.77
#6 16.77 Use "gup [command] --help" for more information about a command.
#6 16.77
#6 16.77 gup:ERROR: unknown flag: --no-exist-option
#6 16.77
#6 16.77 gup:INFO : append bash-completion: /root/.bash_completion
#6 16.77 gup:INFO : append bash-completion: /root/.bash_completion
#6 16.77 gup:INFO : removed testdata/delete/posixer
#6 16.77 gup:INFO : append bash-completion: /root/.bash_completion
#6 16.77 gup:INFO : Export /root/.config/gup/gup.conf
#6 16.77 gup:INFO : create bash-completion file: testdata/.bash_completion
#6 16.77 gup:INFO : create fish-completion file: testdata/.config/fish/completions/gup.fish
#6 16.77 gup:INFO : create zsh-completion file: testdata/.zsh/completion/_gup
#6 16.77 gup:ERROR: testdata/.config/gup/gup.conf is not found
#6 16.77 --- FAIL: TestExecute_Update (0.00s)
#6 16.77 root_test.go:476: rename /go/bin /go/bin.backup: invalid cross-device link
#6 16.77 --- FAIL: TestExecute_Update_DryRun (0.00s)
#6 16.77 root_test.go:569: rename /go/bin /go/bin.backup: invalid cross-device link
#6 16.77 gup:WARN : not found 'test4' package in $GOPATH/bin or $GOBIN
#6 16.77 FAIL
#6 16.77 FAIL github.com/nao1215/gup/cmd 1.908s
#6 16.77 ? github.com/nao1215/gup/internal/assets [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/cmdinfo [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/completion [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/config [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/file [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/goutil [no test files]
#6 16.77 ? github.com/nao1215/gup/internal/notify [no test files]
#6 16.77 ok github.com/nao1215/gup/internal/print 0.011s
#6 16.77 ok github.com/nao1215/gup/internal/slice 0.008s
#6 16.77 FAIL
------
executor failed running [/bin/sh -c git clone https://github.com/nao1215/gup.git && cd gup && go mod download && go test ./...]: exit code: 1 I haven't looked into it in depth, but I have a feeling it is related to this line. Line 161 in b515c5a
It seems to set the |
@KEINOS
However, reproducing the error using Docker may present a different problem. I'm pretty sure the test code is wrong. |
As you said, sadly #43 9e3fc5e did not fix the error on macOS. 😭 This happens while implementing tests. I understand.
I agree. That happens between Windows and macOS too. Many times 😄 My usual work-around for this, to capture error messages during test, is to wrap the error. I use " E.g.: func doSomething(pathDir string) error {
- return os.MkdirAll(pathDir, 0775)
+ if err := os.MkdirAll(pathDir, 0775); err != nil {
+ errors.Wrap(err, "failed to make directory")
+ }
// do the thing
} Like so, the test needs to check only the " Another useful package that I found while using
Solving these problems one by one should raise |
No description provided.