Skip to content

Commit 8976261

Browse files
authored
fix: panic in test introduced by #8453 (#8834)
Signed-off-by: Yoan Blanc <[email protected]>
1 parent b54ab4e commit 8976261

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

nomad/job_endpoint_oss.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
package nomad
44

55
import (
6+
"errors"
67
"fmt"
78
"strings"
89

910
"github.com/hashicorp/nomad/nomad/structs"
1011
vapi "github.com/hashicorp/vault/api"
1112
)
1213

14+
// ErrMultipleNamespaces is send when multiple namespaces are used in the OSS setup
15+
var ErrMultipleNamespaces = errors.New("multiple vault namespaces requires Nomad Enterprise")
16+
1317
// enforceSubmitJob is used to check any Sentinel policies for the submit-job scope
1418
func (j *Job) enforceSubmitJob(override bool, job *structs.Job) (error, error) {
1519
return nil, nil
@@ -51,7 +55,7 @@ func (j *Job) multiVaultNamespaceValidation(
5155
) error {
5256
requestedNamespaces := structs.VaultNamespaceSet(policies)
5357
if len(requestedNamespaces) > 0 {
54-
return fmt.Errorf("multiple vault namespaces requires Nomad Enterprise, Namespaces: %s", strings.Join(requestedNamespaces, ", "))
58+
return fmt.Errorf("%w, Namespaces: %s", ErrMultipleNamespaces, strings.Join(requestedNamespaces, ", "))
5559
}
5660
return nil
5761
}

nomad/job_endpoint_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,9 @@ func TestJobEndpoint_Register_Vault_MultiNamespaces(t *testing.T) {
17361736
var resp structs.JobRegisterResponse
17371737
err := msgpackrpc.CallWithCodec(codec, "Job.Register", req, &resp)
17381738
// OSS or Ent check
1739-
if s1.EnterpriseState.Features() == 0 {
1740-
require.Contains(t, err.Error(), "multiple vault namespaces requires Nomad Enterprise")
1739+
if err != nil && s1.EnterpriseState.Features() == 0 {
1740+
// errors.Is cannot be used because the RPC call break error wrapping.
1741+
require.Contains(t, err.Error(), ErrMultipleNamespaces.Error())
17411742
} else {
17421743
require.NoError(t, err)
17431744
}

0 commit comments

Comments
 (0)