2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2021-07-22 18:58:08 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
2021-01-07 23:47:25 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-03-12 03:51:24 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
2021-01-07 23:47:25 +00:00
|
|
|
)
|
|
|
|
|
2021-01-13 00:45:46 +00:00
|
|
|
var enterpriseMetaField = "EnterpriseMeta"
|
|
|
|
|
2021-01-07 23:47:25 +00:00
|
|
|
func TestServiceID_String(t *testing.T) {
|
|
|
|
t.Run("value", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", sid))
|
|
|
|
})
|
|
|
|
t.Run("pointer", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", &sid))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckID_String(t *testing.T) {
|
|
|
|
t.Run("value", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", cid))
|
|
|
|
})
|
|
|
|
t.Run("pointer", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", &cid))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServiceName_String(t *testing.T) {
|
|
|
|
t.Run("value", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", sn))
|
|
|
|
})
|
|
|
|
t.Run("pointer", func(t *testing.T) {
|
2022-03-12 03:51:24 +00:00
|
|
|
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
|
2021-01-07 23:47:25 +00:00
|
|
|
require.Equal(t, "the-id", fmt.Sprintf("%v", &sn))
|
|
|
|
})
|
|
|
|
}
|
2021-03-18 04:15:48 +00:00
|
|
|
|
|
|
|
func TestIntention_HasWildcardSource(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
ixn := Intention{
|
|
|
|
SourceName: WildcardSpecifier,
|
|
|
|
}
|
|
|
|
require.True(t, ixn.HasWildcardSource())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
ixn := Intention{
|
|
|
|
SourceName: "web",
|
|
|
|
}
|
|
|
|
require.False(t, ixn.HasWildcardSource())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIntention_HasWildcardDestination(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
ixn := Intention{
|
|
|
|
DestinationName: WildcardSpecifier,
|
|
|
|
}
|
|
|
|
require.True(t, ixn.HasWildcardDestination())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
ixn := Intention{
|
|
|
|
DestinationName: "web",
|
|
|
|
}
|
|
|
|
require.False(t, ixn.HasWildcardDestination())
|
|
|
|
})
|
|
|
|
}
|