2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
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"
|
2022-03-15 12:42:43 +00:00
|
|
|
"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) {
|
2022-03-15 12:42:43 +00:00
|
|
|
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 {
|
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) {
|
2022-03-15 12:42:43 +00:00
|
|
|
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")
|
|
|
|
}
|