open-nomad/command/license_get_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.2 KiB
Go
Raw Normal View History

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"
"github.com/hashicorp/nomad/ci"
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) {
ci.Parallel(t)
2020-04-22 13:42:25 +00:00
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 {
require.Equal(t, 0, code)
2020-04-30 12:56:40 +00:00
} else {
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) {
ci.Parallel(t)
2020-07-22 14:21:56 +00:00
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")
}