-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alberto Ricart <[email protected]>
- Loading branch information
Showing
15 changed files
with
444 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,26 +60,10 @@ jobs: | |
go-version: ${{ matrix.go }} | ||
# We're not doing releases, just checks, so we can live without check-latest here | ||
|
||
- name: Export Go environment to Actions outputs | ||
id: go-settings | ||
run: | | ||
echo "::set-output name=arch::$(go env GOARCH)" | ||
echo "::set-output name=hostarch::$(go env GOHOSTARCH)" | ||
echo "::set-output name=os::$(go env GOOS)" | ||
echo "::set-output name=hostos::$(go env GOHOSTOS)" | ||
echo "::set-output name=go-version::$(go env GOVERSION)" | ||
# Use with: | ||
# ${{ steps.go-settings.outputs.go-version }} | ||
# which will look like `go1.17.1` if matrix `1.17.x` matches `1.17.1`. | ||
# These are independent of how the matrix is setup, or if a matrix is even used. | ||
# | ||
# You can see the individual values in the "Set up Go" output, collapsed inside a "go env" group at the end. | ||
|
||
- name: Install additional check/lint tools | ||
id: tools-install | ||
run: | | ||
go install github.com/mattn/goveralls@latest | ||
go install github.com/wadey/gocovmerge@latest | ||
go install honnef.co/go/tools/cmd/[email protected] | ||
if: matrix.canonical | ||
|
||
|
@@ -92,38 +76,22 @@ jobs: | |
- name: Run Tests (with coverage enabled) | ||
id: coverage | ||
run: | | ||
mkdir cov | ||
echo "::group::Coverage of ./cmd" | ||
go test -v -failfast -covermode=atomic -coverprofile=./cov/cmd.out ./cmd | ||
echo "::endgroup::" | ||
echo "::group::Coverage of ./cmd/store" | ||
go test -v -failfast -covermode=atomic -coverprofile=./cov/store.out ./cmd/store | ||
echo "::endgroup::" | ||
go test -v -failfast -coverpkg=./... -coverprofile=./coverage.out ./... | ||
if: runner.os != 'Windows' | ||
|
||
- name: Run Tests (Windows) | ||
id: wintest | ||
# nb2: if we use the coverage approach on Windows, the -coverprofile flag appears to be looked for as a package, and I've no idea why (am not a Windows dev) | ||
# cannot find package "github.com/nats-io/nsc/cov/cmd.out" in any of: | ||
# C:\hostedtoolcache\windows\go\1.16.13\x64\src\github.com\nats-io\nsc\cov\cmd.out (from $GOROOT) | ||
# D:\a\nsc\nsc\go\src\github.com\nats-io\nsc\cov\cmd.out (from $GOPATH) | ||
- name: Run Tests (windows) | ||
run: | | ||
echo "::group::Testing of ./cmd" | ||
go test -v -failfast ./cmd | ||
echo "::endgroup::" | ||
echo "::group::Testing of ./cmd/store" | ||
go test -v -failfast ./cmd/store | ||
echo "::endgroup::" | ||
go test -v -failfast ./... | ||
if: runner.os == 'Windows' | ||
|
||
- name: Upload coverage results | ||
id: coverage-upload | ||
run: | | ||
gocovmerge ./cov/*.out > coverage.out | ||
goveralls -coverprofile=coverage.out -service=github | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
if: matrix.canonical | ||
- name: Upload coverage | ||
uses: coverallsapp/github-action@v2 | ||
continue-on-error: true | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
flag-name: ${{ matrix.module }} | ||
file: ./coverage.out | ||
if: runner.os != 'Windows' | ||
|
||
- name: Bad versions creep defense | ||
id: go-module-versions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/nats-io/cliprompts/v2" | ||
"github.com/nats-io/nsc/v2/cmd/store" | ||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
type tp struct { | ||
AccountUserContextParams | ||
} | ||
|
||
func (p *tp) SetDefaults(ctx ActionCtx) error { | ||
return p.AccountUserContextParams.SetDefaults(ctx) | ||
} | ||
|
||
func (p *tp) Validate(ctx ActionCtx) error { | ||
return p.AccountUserContextParams.Validate(ctx) | ||
} | ||
|
||
func (p *tp) Load(ctx ActionCtx) error { | ||
return nil | ||
} | ||
|
||
func (p *tp) Run(ctx ActionCtx) (store.Status, error) { | ||
return nil, nil | ||
} | ||
|
||
func (p *tp) PreInteractive(ctx ActionCtx) error { | ||
return p.AccountUserContextParams.Edit(ctx) | ||
} | ||
|
||
func (p *tp) PostInteractive(ctx ActionCtx) error { | ||
return nil | ||
} | ||
|
||
func Test_AccountUserContextParams(t *testing.T) { | ||
ts := NewTestStore(t, "O") | ||
defer ts.Done(t) | ||
|
||
ts.AddAccount(t, "A") | ||
ts.AddUser(t, "A", "a") | ||
ts.AddAccount(t, "B") | ||
ts.AddUser(t, "B", "b") | ||
|
||
var params tp | ||
cmd := &cobra.Command{ | ||
Use: "ucp", | ||
SilenceUsage: true, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return RunAction(cmd, args, ¶ms) | ||
}, | ||
} | ||
|
||
cliprompts.LogFn = t.Log | ||
// A, a | ||
inputs := []interface{}{0, 0} | ||
|
||
_, _, err := ExecuteInteractiveCmd(cmd, inputs) | ||
require.NoError(t, err) | ||
require.Equal(t, "A", params.AccountContextParams.Name) | ||
require.Equal(t, "a", params.UserContextParams.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import ( | |
"testing" | ||
|
||
"github.com/nats-io/jwt/v2" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.