2023-02-02 17:15:17 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-09-08 10:06:38 -07:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2023-10-30 14:40:00 -07:00
|
|
|
"time"
|
2021-09-08 10:06:38 -07:00
|
|
|
|
2023-10-30 14:40:00 -07:00
|
|
|
"github.com/hashicorp/boundary/internal/db/timestamp"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/pagination"
|
2021-09-08 10:06:38 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2023-10-30 14:40:00 -07:00
|
|
|
type fakeItem struct {
|
|
|
|
|
pagination.Item
|
|
|
|
|
publicId string
|
|
|
|
|
updateTime time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *fakeItem) GetPublicId() string {
|
|
|
|
|
return p.publicId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *fakeItem) GetUpdateTime() *timestamp.Timestamp {
|
|
|
|
|
return timestamp.New(p.updateTime)
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 10:06:38 -07:00
|
|
|
func Test_GetOpts(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
2021-10-29 15:35:06 -04:00
|
|
|
t.Run("WithPublicId", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithPublicId("test"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withPublicId = "test"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-09-08 10:06:38 -07:00
|
|
|
t.Run("WithName", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithName("test"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withName = "test"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-11-11 11:28:08 -05:00
|
|
|
t.Run("WithSyncIntervalSeconds", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithSyncIntervalSeconds(5))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withSyncIntervalSeconds = 5
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-10-20 12:20:28 -07:00
|
|
|
t.Run("WithPluginId", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(withPluginId("test"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withPluginId = "test"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-09-08 10:06:38 -07:00
|
|
|
t.Run("WithDescription", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithDescription("test desc"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withDescription = "test desc"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-10-20 12:20:28 -07:00
|
|
|
t.Run("WithLimit", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithLimit(5))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withLimit = 5
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-09-20 12:48:38 -04:00
|
|
|
t.Run("WithPreferredEndpoints", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithPreferredEndpoints([]string{"foo"}))
|
2021-09-08 10:06:38 -07:00
|
|
|
testOpts := getDefaultOptions()
|
2021-09-20 12:48:38 -04:00
|
|
|
testOpts.withPreferredEndpoints = []string{"foo"}
|
|
|
|
|
assert.EqualValues(t, opts, testOpts)
|
2021-09-08 10:06:38 -07:00
|
|
|
})
|
2021-10-20 12:20:28 -07:00
|
|
|
t.Run("withDnsNames", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(withDnsNames([]string{"foo"}))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withDnsNames = []string{"foo"}
|
|
|
|
|
assert.EqualValues(t, opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
t.Run("withIpAddresses", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(withIpAddresses([]string{"foo"}))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withIpAddresses = []string{"foo"}
|
|
|
|
|
assert.EqualValues(t, opts, testOpts)
|
|
|
|
|
})
|
2021-10-28 10:09:43 -04:00
|
|
|
t.Run("withSetIds", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithSetIds([]string{"foo"}))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withSetIds = []string{"foo"}
|
|
|
|
|
assert.EqualValues(t, opts, testOpts)
|
|
|
|
|
})
|
2021-11-16 18:54:38 -05:00
|
|
|
t.Run("WithSecretsHmac", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithSecretsHmac([]byte("secrets-hmac")))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withSecretsHmac = []byte("secrets-hmac")
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2023-03-10 18:07:32 +00:00
|
|
|
t.Run("WithExternalName", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithExternalName("external-name"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withExternalName = "external-name"
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2023-10-30 14:40:00 -07:00
|
|
|
t.Run("WithStartPageAfterItem", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
updateTime := time.Now()
|
|
|
|
|
opts := getOpts(WithStartPageAfterItem(&fakeItem{nil, "s_1", updateTime}))
|
|
|
|
|
assert.Equal(opts.withStartPageAfterItem.GetPublicId(), "s_1")
|
|
|
|
|
assert.Equal(opts.withStartPageAfterItem.GetUpdateTime(), timestamp.New(updateTime))
|
|
|
|
|
})
|
2024-07-26 12:50:55 +01:00
|
|
|
t.Run("WithWorkerFilter", func(t *testing.T) {
|
|
|
|
|
opts := getOpts(WithWorkerFilter(`"test" in "/tags/type"`))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withWorkerFilter = `"test" in "/tags/type"`
|
|
|
|
|
assert.Equal(t, opts, testOpts)
|
|
|
|
|
})
|
2021-09-08 10:06:38 -07:00
|
|
|
}
|