consul/agent/structs/structs_ce_test.go

83 lines
1.9 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
[COMPLIANCE] License changes (#18443) * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 13:12:13 +00:00
// SPDX-License-Identifier: BUSL-1.1
//go:build !consulent
package structs
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/acl"
)
var enterpriseMetaField = "EnterpriseMeta"
func TestServiceID_String(t *testing.T) {
t.Run("value", func(t *testing.T) {
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", sid))
})
t.Run("pointer", func(t *testing.T) {
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", &sid))
})
}
func TestCheckID_String(t *testing.T) {
t.Run("value", func(t *testing.T) {
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", cid))
})
t.Run("pointer", func(t *testing.T) {
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", &cid))
})
}
func TestServiceName_String(t *testing.T) {
t.Run("value", func(t *testing.T) {
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", sn))
})
t.Run("pointer", func(t *testing.T) {
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
require.Equal(t, "the-id", fmt.Sprintf("%v", &sn))
})
}
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())
})
}