mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 03:45:41 +03:00
test all commands oss err
This commit is contained in:
@@ -2,19 +2,15 @@ package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
var _ cli.Command = &LicenseGetCommand{}
|
||||
|
||||
type LicenseGetCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
func (c *LicenseGetCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: nomad license put [options]
|
||||
Usage: nomad license get [options]
|
||||
|
||||
Gets a new license in Servers and Clients
|
||||
General Options:
|
||||
@@ -44,16 +40,22 @@ func (c *LicenseGetCommand) Run(args []string) int {
|
||||
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
||||
flags.BoolVar(&signed, "signed", false, "Gets the signed license blob instead of a parsed license")
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error parsing flags: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
client, err := c.Meta.Client()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
||||
return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
if signed {
|
||||
resp, _, err := client.Operator().LicenseGetSigned(nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error getting signed license: %v", err))
|
||||
return 1
|
||||
}
|
||||
c.Ui.Output(resp)
|
||||
return 0
|
||||
@@ -61,8 +63,8 @@ func (c *LicenseGetCommand) Run(args []string) int {
|
||||
|
||||
resp, _, err := client.Operator().LicenseGet(nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error putting license: %v", err))
|
||||
return 0
|
||||
c.Ui.Error(fmt.Sprintf("Error getting license: %v", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
return OutputLicenseReply(c.Ui, resp)
|
||||
|
||||
27
command/license_get_test.go
Normal file
27
command/license_get_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ cli.Command = &LicenseGetCommand{}
|
||||
|
||||
func TestCommand_LicenseGet_OSSErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &LicenseGetCommand{Meta: Meta{Ui: ui}}
|
||||
|
||||
if code := cmd.Run([]string{"-address=" + url}); code != 1 {
|
||||
require.Equal(t, 1, code)
|
||||
}
|
||||
|
||||
require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
|
||||
|
||||
}
|
||||
54
command/license_reset.go
Normal file
54
command/license_reset.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type LicenseResetCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
func (c *LicenseResetCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: nomad license reset [options]
|
||||
|
||||
Resets the Nomad Server and Clients Enterprise license to the builtin one if
|
||||
it is still valid. IF the builtin license is invalid, the current one stays
|
||||
active.
|
||||
|
||||
General Options:
|
||||
|
||||
` + generalOptionsUsage()
|
||||
|
||||
return helpText
|
||||
}
|
||||
|
||||
func (c *LicenseResetCommand) Synopsis() string {
|
||||
return "Install a new Nomad Enterprise License"
|
||||
}
|
||||
|
||||
func (c *LicenseResetCommand) Name() string { return "license reset" }
|
||||
|
||||
func (c *LicenseResetCommand) Run(args []string) int {
|
||||
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
||||
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error parsing flags: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
client, err := c.Meta.Client()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
resp, _, err := client.Operator().LicenseReset(nil)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error resetting license: %v", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
return OutputLicenseReply(c.Ui, resp)
|
||||
}
|
||||
27
command/license_reset_test.go
Normal file
27
command/license_reset_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ cli.Command = &LicenseResetCommand{}
|
||||
|
||||
func TestCommand_LicenseReset_OSSErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &LicenseResetCommand{Meta: Meta{Ui: ui}}
|
||||
|
||||
if code := cmd.Run([]string{"-address=" + url}); code != 1 {
|
||||
require.Equal(t, 1, code)
|
||||
}
|
||||
|
||||
require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user