github.com/hernad/nomad@v1.6.112/command/license_get_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package command
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/hernad/nomad/api"
    11  	"github.com/hernad/nomad/ci"
    12  	"github.com/mitchellh/cli"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  var _ cli.Command = &LicenseGetCommand{}
    17  
    18  func TestCommand_LicenseGet_OSSErr(t *testing.T) {
    19  	ci.Parallel(t)
    20  
    21  	srv, _, url := testServer(t, false, nil)
    22  	defer srv.Shutdown()
    23  
    24  	ui := cli.NewMockUi()
    25  	cmd := &LicenseGetCommand{Meta: Meta{Ui: ui}}
    26  
    27  	code := cmd.Run([]string{"-address=" + url})
    28  	if srv.Enterprise {
    29  		require.Equal(t, 0, code)
    30  	} else {
    31  		require.Equal(t, 1, code)
    32  		require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
    33  	}
    34  }
    35  
    36  func TestOutputLicenseReply(t *testing.T) {
    37  	ci.Parallel(t)
    38  
    39  	now := time.Now()
    40  	lic := &api.LicenseReply{
    41  		License: &api.License{
    42  			LicenseID:       "licenseID",
    43  			CustomerID:      "customerID",
    44  			InstallationID:  "*",
    45  			IssueTime:       now,
    46  			StartTime:       now,
    47  			ExpirationTime:  now.Add(1 * time.Hour),
    48  			TerminationTime: now,
    49  			Product:         "nomad",
    50  			Flags: map[string]interface{}{
    51  				"": nil,
    52  			},
    53  		},
    54  	}
    55  
    56  	ui := cli.NewMockUi()
    57  
    58  	require.Equal(t, 0, OutputLicenseReply(ui, lic))
    59  
    60  	out := ui.OutputWriter.String()
    61  	require.Contains(t, out, "Customer ID")
    62  	require.Contains(t, out, "License ID")
    63  }