-
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
13 changed files
with
431 additions
and
37 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 |
---|---|---|
@@ -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
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.