2020-04-22 13:42:25 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-07-22 14:21:56 +00:00
|
|
|
"time"
|
2020-04-22 13:42:25 +00:00
|
|
|
|
2020-07-22 14:21:56 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
2020-04-22 13:42:25 +00:00
|
|
|
"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()
|
|
|
|
|
2020-10-05 14:07:41 +00:00
|
|
|
ui := cli.NewMockUi()
|
2020-04-22 13:42:25 +00:00
|
|
|
cmd := &LicenseGetCommand{Meta: Meta{Ui: ui}}
|
|
|
|
|
2020-04-30 12:56:40 +00:00
|
|
|
code := cmd.Run([]string{"-address=" + url})
|
|
|
|
if srv.Enterprise {
|
2020-05-05 14:28:58 +00:00
|
|
|
require.Equal(t, 0, code)
|
2020-04-30 12:56:40 +00:00
|
|
|
} else {
|
2020-05-05 14:28:58 +00:00
|
|
|
require.Equal(t, 1, code)
|
2020-04-30 12:56:40 +00:00
|
|
|
require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
|
|
|
|
}
|
2020-04-22 13:42:25 +00:00
|
|
|
}
|
2020-07-22 14:21:56 +00:00
|
|
|
|
|
|
|
func TestOutputLicenseReply(t *testing.T) {
|
|
|
|
now := time.Now()
|
|
|
|
lic := &api.LicenseReply{
|
|
|
|
License: &api.License{
|
|
|
|
LicenseID: "licenseID",
|
|
|
|
CustomerID: "customerID",
|
|
|
|
InstallationID: "*",
|
|
|
|
IssueTime: now,
|
|
|
|
StartTime: now,
|
|
|
|
ExpirationTime: now.Add(1 * time.Hour),
|
|
|
|
TerminationTime: now,
|
|
|
|
Product: "nomad",
|
|
|
|
Flags: map[string]interface{}{
|
|
|
|
"": nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-05 14:07:41 +00:00
|
|
|
ui := cli.NewMockUi()
|
2020-07-22 14:21:56 +00:00
|
|
|
|
|
|
|
require.Equal(t, 0, OutputLicenseReply(ui, lic))
|
|
|
|
|
|
|
|
out := ui.OutputWriter.String()
|
|
|
|
require.Contains(t, out, "Customer ID")
|
|
|
|
require.Contains(t, out, "License ID")
|
|
|
|
}
|