Skip to content

Commit

Permalink
test(cmd): introduce tests using config files
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido committed Mar 23, 2023
1 parent b27cbfc commit 6b19480
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
86 changes: 84 additions & 2 deletions cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"os"
"path"
"strings"
"testing"

Expand All @@ -38,6 +39,8 @@ type testCase struct {
}

func TestChildCommands(t *testing.T) {
cwd, _ := os.Getwd()

cases := []testCase{
{
cmdline: []string{"in"},
Expand Down Expand Up @@ -109,6 +112,29 @@ Global Flags:
"reporter": null,
"timeout": 60
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_TIMEOUT": "9999",
},
cmdline: []string{"in", "--debug-options", "--timeout", "8888"},
stdout: heredoc.Doc(`{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"gh-owner": "",
"gh-pull-id": 0,
"gh-repo": "",
"gh-token": "",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://registry.npmjs.org",
"reporter": null,
"timeout": 8888
}
`),
stderr: "Running without a configuration file\n",
errstr: "",
Expand Down Expand Up @@ -299,6 +325,64 @@ Global Flags:
stderr: "Running without a configuration file\n",
errstr: "",
},
{
cmdline: []string{"scan", "--debug-options", "--config", path.Join(cwd, "testdata", "c1.yaml")},
stdout: heredoc.Doc(`Using config file: _CWD_/testdata/c1.yaml
{
"debug-options": true,
"endpoint": "https://npm.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 78999,
"gh-repo": "go-urn",
"gh-token": "zzz",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://some.io",
"reporter": [
33
],
"timeout": 2222
}
`),
stderr: "",
errstr: "",
},
{
envvar: map[string]string{
"LSTN_GH_PULL_ID": "887755",
"LSTN_GH_REPO": "go-conventionalcommits",
"LSTN_ENDPOINT": "https://npm-stage.listen.dev",
"LSTN_TIMEOUT": "33331",
},
cmdline: []string{"scan", "--debug-options", "--config", path.Join(cwd, "testdata", "c1.yaml")},
stdout: heredoc.Doc(`Using config file: _CWD_/testdata/c1.yaml
{
"debug-options": true,
"endpoint": "https://npm-stage.listen.dev",
"exclude": [
110
],
"gh-owner": "leodido",
"gh-pull-id": 887755,
"gh-repo": "go-conventionalcommits",
"gh-token": "zzz",
"jq": "",
"json": false,
"loglevel": "info",
"npm-registry": "https://some.io",
"reporter": [
33
],
"timeout": 33331
}
`),
stderr: "",
errstr: "",
},
{
cmdline: []string{"version", "--debug-options"},
stdout: heredoc.Doc(`{
Expand Down Expand Up @@ -334,8 +418,6 @@ Global Flags:
},
}

cwd, _ := os.Getwd()

for _, tc := range cases {
tc := tc

Expand Down
13 changes: 13 additions & 0 deletions cmd/testdata/c1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
timeout: 2222
token:
github: zzz
registry:
npm: https://some.io
reporter:
types:
- gh-pull-review
github:
owner: leodido
pull:
id: 78999
repo: go-urn

0 comments on commit 6b19480

Please sign in to comment.