2019-03-19 22:56:17 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-07-01 20:23:36 +00:00
|
|
|
"time"
|
2019-03-19 22:56:17 +00:00
|
|
|
|
2019-04-07 06:38:08 +00:00
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
2019-03-27 23:52:38 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-02-03 23:10:38 +00:00
|
|
|
|
2022-02-22 16:36:36 +00:00
|
|
|
"github.com/hashicorp/consul/agent/configentry"
|
2021-02-03 23:10:38 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2019-03-19 22:56:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStore_ConfigEntry(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2019-03-19 22:56:17 +00:00
|
|
|
|
|
|
|
expected := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
2019-03-27 23:52:38 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"DestinationServiceName": "foo",
|
2019-03-19 22:56:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, expected))
|
2019-03-19 22:56:17 +00:00
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err := s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(0), idx)
|
|
|
|
require.Equal(t, expected, config)
|
2019-03-19 22:56:17 +00:00
|
|
|
|
|
|
|
// Update
|
|
|
|
updated := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
2019-03-27 23:52:38 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"DestinationServiceName": "bar",
|
2019-03-19 22:56:17 +00:00
|
|
|
},
|
|
|
|
}
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, updated))
|
2019-03-19 22:56:17 +00:00
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err = s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), idx)
|
|
|
|
require.Equal(t, updated, config)
|
2019-03-19 22:56:17 +00:00
|
|
|
|
|
|
|
// Delete
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.DeleteConfigEntry(2, structs.ProxyDefaults, "global", nil))
|
2019-03-27 23:52:38 +00:00
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err = s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), idx)
|
|
|
|
require.Nil(t, config)
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
// Set up a watch.
|
|
|
|
serviceConf := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "foo",
|
|
|
|
}
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(3, serviceConf))
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
2020-01-24 15:04:58 +00:00
|
|
|
_, _, err = s.ConfigEntry(ws, structs.ServiceDefaults, "foo", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
// Make an unrelated modification and make sure the watch doesn't fire.
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(4, updated))
|
|
|
|
require.False(t, watchFired(ws))
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
// Update the watched config and make sure it fires.
|
|
|
|
serviceConf.Protocol = "http"
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(5, serviceConf))
|
|
|
|
require.True(t, watchFired(ws))
|
2019-03-27 23:52:38 +00:00
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
}
|
2019-03-27 23:52:38 +00:00
|
|
|
func TestStore_ConfigEntryCAS(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
expected := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"DestinationServiceName": "foo",
|
|
|
|
},
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 23:52:38 +00:00
|
|
|
// Create
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, expected))
|
2019-03-27 23:52:38 +00:00
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err := s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), idx)
|
|
|
|
require.Equal(t, expected, config)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Update with invalid index
|
|
|
|
updated := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"DestinationServiceName": "bar",
|
|
|
|
},
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
ok, err := s.EnsureConfigEntryCAS(2, 99, updated)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.False(t, ok)
|
|
|
|
require.NoError(t, err)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Entry should not be changed
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err = s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), idx)
|
|
|
|
require.Equal(t, expected, config)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Update with a valid index
|
2021-02-03 23:10:38 +00:00
|
|
|
ok, err = s.EnsureConfigEntryCAS(2, 1, updated)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
require.NoError(t, err)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Entry should be updated
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, config, err = s.ConfigEntry(nil, structs.ProxyDefaults, "global", nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), idx)
|
|
|
|
require.Equal(t, updated, config)
|
2019-03-27 23:52:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 16:42:01 +00:00
|
|
|
func TestStore_ConfigEntry_DeleteCAS(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
entry := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"DestinationServiceName": "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to delete the entry before it exists.
|
|
|
|
ok, err := s.DeleteConfigEntryCAS(1, 0, entry)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2021-11-01 16:42:01 +00:00
|
|
|
|
|
|
|
// Create the entry.
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, entry))
|
2021-11-01 16:42:01 +00:00
|
|
|
|
|
|
|
// Attempt to delete with an invalid index.
|
|
|
|
ok, err = s.DeleteConfigEntryCAS(2, 99, entry)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2021-11-01 16:42:01 +00:00
|
|
|
|
|
|
|
// Entry should not be deleted.
|
|
|
|
_, config, err := s.ConfigEntry(nil, entry.Kind, entry.Name, nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, config)
|
2021-11-01 16:42:01 +00:00
|
|
|
|
|
|
|
// Attempt to delete with a valid index.
|
|
|
|
ok, err = s.DeleteConfigEntryCAS(2, 1, entry)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ok)
|
2021-11-01 16:42:01 +00:00
|
|
|
|
|
|
|
// Entry should be deleted.
|
|
|
|
_, config, err = s.ConfigEntry(nil, entry.Kind, entry.Name, nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, config)
|
2021-11-01 16:42:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 18:24:05 +00:00
|
|
|
func TestStore_ConfigEntry_UpdateOver(t *testing.T) {
|
|
|
|
// This test uses ServiceIntentions because they are the only
|
|
|
|
// kind that implements UpdateOver() at this time.
|
|
|
|
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
var (
|
|
|
|
idA = testUUID()
|
|
|
|
idB = testUUID()
|
|
|
|
|
|
|
|
loc = time.FixedZone("UTC-8", -8*60*60)
|
|
|
|
timeA = time.Date(1955, 11, 5, 6, 15, 0, 0, loc)
|
|
|
|
timeB = time.Date(1985, 10, 26, 1, 35, 0, 0, loc)
|
|
|
|
)
|
|
|
|
require.NotEqual(t, idA, idB)
|
|
|
|
|
|
|
|
initial := &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{
|
|
|
|
LegacyID: idA,
|
|
|
|
Name: "web",
|
|
|
|
Action: structs.IntentionActionAllow,
|
|
|
|
LegacyCreateTime: &timeA,
|
|
|
|
LegacyUpdateTime: &timeA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
nextIndex := uint64(1)
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(nextIndex, initial.Clone()))
|
2020-10-06 18:24:05 +00:00
|
|
|
|
|
|
|
idx, raw, err := s.ConfigEntry(nil, structs.ServiceIntentions, "api", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, nextIndex, idx)
|
|
|
|
|
|
|
|
got, ok := raw.(*structs.ServiceIntentionsConfigEntry)
|
|
|
|
require.True(t, ok)
|
|
|
|
initial.RaftIndex = got.RaftIndex
|
|
|
|
require.Equal(t, initial, got)
|
|
|
|
|
|
|
|
t.Run("update and fail change legacyID", func(t *testing.T) {
|
|
|
|
// Update
|
|
|
|
updated := &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{
|
|
|
|
LegacyID: idB,
|
|
|
|
Name: "web",
|
|
|
|
Action: structs.IntentionActionDeny,
|
|
|
|
LegacyCreateTime: &timeB,
|
|
|
|
LegacyUpdateTime: &timeB,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
nextIndex++
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(nextIndex, updated.Clone())
|
2020-10-06 18:24:05 +00:00
|
|
|
testutil.RequireErrorContains(t, err, "cannot set this field to a different value")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update and do not update create time", func(t *testing.T) {
|
|
|
|
// Update
|
|
|
|
updated := &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{
|
|
|
|
LegacyID: idA,
|
|
|
|
Name: "web",
|
|
|
|
Action: structs.IntentionActionDeny,
|
|
|
|
LegacyCreateTime: &timeB,
|
|
|
|
LegacyUpdateTime: &timeB,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
nextIndex++
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(nextIndex, updated.Clone()))
|
2020-10-06 18:24:05 +00:00
|
|
|
|
|
|
|
// check
|
|
|
|
idx, raw, err = s.ConfigEntry(nil, structs.ServiceIntentions, "api", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, nextIndex, idx)
|
|
|
|
|
|
|
|
got, ok = raw.(*structs.ServiceIntentionsConfigEntry)
|
|
|
|
require.True(t, ok)
|
|
|
|
updated.RaftIndex = got.RaftIndex
|
|
|
|
updated.Sources[0].LegacyCreateTime = &timeA // UpdateOver will not replace this
|
|
|
|
require.Equal(t, updated, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-27 23:52:38 +00:00
|
|
|
func TestStore_ConfigEntries(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Create some config entries.
|
|
|
|
entry1 := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "test1",
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
2019-03-27 23:52:38 +00:00
|
|
|
entry2 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "test2",
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
2019-04-07 06:38:08 +00:00
|
|
|
entry3 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "test3",
|
|
|
|
}
|
2019-03-27 23:52:38 +00:00
|
|
|
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, entry1))
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, entry2))
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(2, entry3))
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Get all entries
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, entries, err := s.ConfigEntries(nil, nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), idx)
|
|
|
|
require.Equal(t, []structs.ConfigEntry{entry1, entry2, entry3}, entries)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Get all proxy entries
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, entries, err = s.ConfigEntriesByKind(nil, structs.ProxyDefaults, nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), idx)
|
|
|
|
require.Equal(t, []structs.ConfigEntry{entry1}, entries)
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
// Get all service entries
|
2019-04-07 06:38:08 +00:00
|
|
|
ws := memdb.NewWatchSet()
|
2020-01-24 15:04:58 +00:00
|
|
|
idx, entries, err = s.ConfigEntriesByKind(ws, structs.ServiceDefaults, nil)
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), idx)
|
|
|
|
require.Equal(t, []structs.ConfigEntry{entry2, entry3}, entries)
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
// Watch should not have fired
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.False(t, watchFired(ws))
|
2019-04-07 06:38:08 +00:00
|
|
|
|
|
|
|
// Now make an update and make sure the watch fires.
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(3, &structs.ServiceConfigEntry{
|
2019-04-07 06:38:08 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "test2",
|
|
|
|
Protocol: "tcp",
|
2021-02-03 23:10:38 +00:00
|
|
|
}))
|
bulk rewrite using this script
set -euo pipefail
unset CDPATH
cd "$(dirname "$0")"
for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do
echo "=== require: $f ==="
sed -i '/require := require.New(t)/d' $f
# require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f
# require.XXX(tblah) but not require.XXX(t, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f
# require.XXX(rblah) but not require.XXX(r, blah)
sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f
gofmt -s -w $f
done
for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do
echo "=== assert: $f ==="
sed -i '/assert := assert.New(t)/d' $f
# assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f
# assert.XXX(tblah) but not assert.XXX(t, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f
# assert.XXX(rblah) but not assert.XXX(r, blah)
sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f
gofmt -s -w $f
done
2022-01-20 16:46:23 +00:00
|
|
|
require.True(t, watchFired(ws))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_ServiceDefaults_Kind_Destination(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "dest1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
destination := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "dest1",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, destination))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindDestination)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err := s.ServiceNamesOfKind(ws, structs.ServiceKindDestination)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindDestination)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(6, structs.ServiceDefaults, destination.Name, &destination.EnterpriseMeta))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
2022-08-08 17:44:18 +00:00
|
|
|
require.Equal(t, structs.GatewayServiceKindUnknown, gatewayServices[0].ServiceKind)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err = s.ServiceNamesOfKind(ws, structs.ServiceKindDestination)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 0)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_ServiceDefaults_Kind_NotDestination(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "dest1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
destination := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "dest1",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, destination))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(6, structs.ServiceDefaults, destination.Name, &destination.EnterpriseMeta))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_Service_TerminatingGateway_Kind_Service_Destination(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
service := &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTypical,
|
|
|
|
Service: "web",
|
|
|
|
}
|
|
|
|
destination := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureNode(0, &structs.Node{Node: "node1"}))
|
|
|
|
require.NoError(t, s.EnsureService(0, "node1", service))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindService)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err := s.ServiceNamesOfKind(ws, structs.ServiceKindTypical)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindTypical)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, destination))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindService)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err = s.ServiceNamesOfKind(ws, structs.ServiceKindTypical)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindTypical)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteService(6, "node1", service.ID, &service.EnterpriseMeta, ""))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindDestination)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err = s.ServiceNamesOfKind(ws, structs.ServiceKindDestination)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindDestination)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_Service_TerminatingGateway_Kind_Destination_Service(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
service := &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTypical,
|
|
|
|
Service: "web",
|
|
|
|
}
|
|
|
|
destination := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, destination))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindDestination)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err := s.ServiceNamesOfKind(ws, structs.ServiceKindDestination)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindDestination)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
require.NoError(t, s.EnsureNode(0, &structs.Node{Node: "node1"}))
|
|
|
|
require.NoError(t, s.EnsureService(0, "node1", service))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindService)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err = s.ServiceNamesOfKind(ws, structs.ServiceKindTypical)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindTypical)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteService(6, "node1", service.ID, &service.EnterpriseMeta, ""))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindDestination)
|
|
|
|
|
2022-06-07 19:03:59 +00:00
|
|
|
_, kindServices, err = s.ServiceNamesOfKind(ws, structs.ServiceKindDestination)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, kindServices, 1)
|
|
|
|
require.Equal(t, kindServices[0].Kind, structs.ServiceKindDestination)
|
|
|
|
|
2022-05-31 20:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_Service_TerminatingGateway_Kind_Service(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
service := &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTypical,
|
|
|
|
Service: "web",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureNode(0, &structs.Node{Node: "node1"}))
|
|
|
|
require.NoError(t, s.EnsureService(0, "node1", service))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindService)
|
|
|
|
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteService(6, "node1", service.ID, &service.EnterpriseMeta, ""))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindUnknown)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_ServiceDefaults_Kind_Destination_Wildcard(t *testing.T) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
destination := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "dest1",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 0)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, destination))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindDestination)
|
|
|
|
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(6, structs.ServiceDefaults, destination.Name, &destination.EnterpriseMeta))
|
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Watch is fired because we deleted the destination - now the mapping should be gone.
|
2022-05-31 20:20:12 +00:00
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
2022-08-08 17:44:18 +00:00
|
|
|
require.Len(t, gatewayServices, 0)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
t.Run("delete service instance before config entry", func(t *testing.T) {
|
|
|
|
// Set up a service with both a real instance and destination from a config entry.
|
|
|
|
require.NoError(t, s.EnsureNode(7, &structs.Node{Node: "foo", Address: "127.0.0.1"}))
|
|
|
|
require.NoError(t, s.EnsureService(8, "foo", &structs.NodeService{ID: "dest2", Service: "dest2", Tags: nil, Address: "", Port: 5000}))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, structs.GatewayServiceKindService, gatewayServices[0].ServiceKind)
|
|
|
|
|
|
|
|
// Register destination; shouldn't change the gateway mapping.
|
|
|
|
destination2 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "dest2",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(9, destination2))
|
|
|
|
require.False(t, watchFired(ws))
|
|
|
|
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
expected := structs.GatewayServices{
|
2022-05-31 20:20:12 +00:00
|
|
|
{
|
2022-08-08 17:44:18 +00:00
|
|
|
Service: structs.NewServiceName("dest2", nil),
|
|
|
|
Gateway: structs.NewServiceName("Gtwy1", nil),
|
|
|
|
ServiceKind: structs.GatewayServiceKindService,
|
|
|
|
GatewayKind: structs.ServiceKindTerminatingGateway,
|
|
|
|
FromWildcard: true,
|
|
|
|
RaftIndex: structs.RaftIndex{
|
|
|
|
CreateIndex: 8,
|
|
|
|
ModifyIndex: 8,
|
|
|
|
},
|
2022-05-31 20:20:12 +00:00
|
|
|
},
|
2022-08-08 17:44:18 +00:00
|
|
|
}
|
|
|
|
require.Equal(t, expected, gatewayServices)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Delete the service, mapping should still exist.
|
|
|
|
require.NoError(t, s.DeleteService(10, "foo", "dest2", nil, ""))
|
|
|
|
require.False(t, watchFired(ws))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, expected, gatewayServices)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Delete the config entry, mapping should be gone.
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(11, structs.ServiceDefaults, "dest2", &destination.EnterpriseMeta))
|
|
|
|
require.True(t, watchFired(ws))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, gatewayServices)
|
|
|
|
})
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
t.Run("delete config entry before service instance", func(t *testing.T) {
|
|
|
|
// Set up a service with both a real instance and destination from a config entry.
|
|
|
|
destination2 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "dest2",
|
|
|
|
Destination: &structs.DestinationConfig{},
|
|
|
|
}
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(7, destination2))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
expected := structs.GatewayServices{
|
|
|
|
{
|
|
|
|
Service: structs.NewServiceName("dest2", nil),
|
|
|
|
Gateway: structs.NewServiceName("Gtwy1", nil),
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
GatewayKind: structs.ServiceKindTerminatingGateway,
|
|
|
|
FromWildcard: true,
|
|
|
|
RaftIndex: structs.RaftIndex{
|
|
|
|
CreateIndex: 7,
|
|
|
|
ModifyIndex: 7,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.Equal(t, expected, gatewayServices)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Register service, only ServiceKind should have changed on the gateway mapping.
|
|
|
|
require.NoError(t, s.EnsureNode(8, &structs.Node{Node: "foo", Address: "127.0.0.1"}))
|
|
|
|
require.NoError(t, s.EnsureService(9, "foo", &structs.NodeService{ID: "dest2", Service: "dest2", Tags: nil, Address: "", Port: 5000}))
|
|
|
|
require.True(t, watchFired(ws))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
expected = structs.GatewayServices{
|
|
|
|
{
|
|
|
|
Service: structs.NewServiceName("dest2", nil),
|
|
|
|
Gateway: structs.NewServiceName("Gtwy1", nil),
|
|
|
|
ServiceKind: structs.GatewayServiceKindService,
|
|
|
|
GatewayKind: structs.ServiceKindTerminatingGateway,
|
|
|
|
FromWildcard: true,
|
|
|
|
RaftIndex: structs.RaftIndex{
|
|
|
|
CreateIndex: 7,
|
|
|
|
ModifyIndex: 9,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.Equal(t, expected, gatewayServices)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Delete the config entry, mapping should still exist.
|
|
|
|
require.NoError(t, s.DeleteConfigEntry(10, structs.ServiceDefaults, "dest2", &destination.EnterpriseMeta))
|
|
|
|
require.False(t, watchFired(ws))
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, expected, gatewayServices)
|
2022-05-31 20:20:12 +00:00
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
// Delete the service, mapping should be gone.
|
|
|
|
require.NoError(t, s.DeleteService(11, "foo", "dest2", nil, ""))
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, gatewayServices)
|
|
|
|
})
|
2022-05-31 20:20:12 +00:00
|
|
|
}
|
|
|
|
|
2022-08-08 17:44:18 +00:00
|
|
|
func TestStore_Service_TerminatingGateway_Kind_Service_Wildcard(t *testing.T) {
|
2022-05-31 20:20:12 +00:00
|
|
|
s := testConfigStateStore(t)
|
|
|
|
|
|
|
|
Gtwy := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "Gtwy1",
|
|
|
|
Services: []structs.LinkedService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, Gtwy))
|
|
|
|
|
|
|
|
service := &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTypical,
|
|
|
|
Service: "web",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, gatewayServices, err := s.GatewayServices(nil, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 0)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create
|
|
|
|
require.NoError(t, s.EnsureNode(0, &structs.Node{Node: "node1"}))
|
|
|
|
require.NoError(t, s.EnsureService(0, "node1", service))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 1)
|
|
|
|
require.Equal(t, gatewayServices[0].ServiceKind, structs.GatewayServiceKindService)
|
|
|
|
|
|
|
|
ws = memdb.NewWatchSet()
|
|
|
|
_, _, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, s.DeleteService(6, "node1", service.ID, &service.EnterpriseMeta, ""))
|
|
|
|
|
|
|
|
//Watch is fired because we transitioned to a destination, by default we assume it's not.
|
|
|
|
require.True(t, watchFired(ws))
|
|
|
|
|
|
|
|
_, gatewayServices, err = s.GatewayServices(ws, "Gtwy1", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, gatewayServices, 0)
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
2019-07-01 20:23:36 +00:00
|
|
|
|
|
|
|
func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
|
2022-07-12 16:03:41 +00:00
|
|
|
ensureConfigEntry := func(s *Store, idx uint64, entry structs.ConfigEntry) error {
|
|
|
|
if err := entry.Normalize(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := entry.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-24 16:48:02 +00:00
|
|
|
return s.EnsureConfigEntry(idx, entry)
|
2022-07-12 16:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
type tcase struct {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries []structs.ConfigEntry
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd structs.ConfigEntry
|
|
|
|
opDelete configentry.KindName
|
2019-07-01 20:23:36 +00:00
|
|
|
expectErr string
|
|
|
|
expectGraphErr bool
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
2022-07-12 16:03:41 +00:00
|
|
|
|
|
|
|
EMPTY_KN := configentry.KindName{}
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc tcase) {
|
|
|
|
s := testConfigStateStore(t)
|
|
|
|
for _, entry := range tc.entries {
|
|
|
|
require.NoError(t, ensureConfigEntry(s, 0, entry))
|
|
|
|
}
|
|
|
|
|
|
|
|
nOps := 0
|
|
|
|
if tc.opAdd != nil {
|
|
|
|
nOps++
|
|
|
|
}
|
|
|
|
if tc.opDelete != EMPTY_KN {
|
|
|
|
nOps++
|
|
|
|
}
|
|
|
|
require.Equal(t, 1, nOps, "exactly one operation is required")
|
|
|
|
|
|
|
|
var err error
|
|
|
|
switch {
|
|
|
|
case tc.opAdd != nil:
|
|
|
|
err = ensureConfigEntry(s, 0, tc.opAdd)
|
|
|
|
case tc.opDelete != EMPTY_KN:
|
|
|
|
kn := tc.opDelete
|
|
|
|
err = s.DeleteConfigEntry(0, kn.Kind, kn.Name, &kn.EnterpriseMeta)
|
|
|
|
default:
|
|
|
|
t.Fatal("not possible")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), tc.expectErr)
|
|
|
|
_, ok := err.(*structs.ConfigEntryGraphError)
|
|
|
|
if tc.expectGraphErr {
|
|
|
|
require.True(t, ok, "%T is not a *ConfigEntryGraphError", err)
|
|
|
|
} else {
|
|
|
|
require.False(t, ok, "did not expect a *ConfigEntryGraphError here: %v", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
cases := map[string]tcase{
|
2020-06-16 17:19:31 +00:00
|
|
|
"splitter fails without default protocol": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"splitter fails with tcp protocol": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"splitter works with http protocol": {
|
2019-07-02 16:01:17 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "tcp", // loses
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
2020-01-24 15:04:58 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
|
2020-01-24 15:04:58 +00:00
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
|
|
|
},
|
|
|
|
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"splitter works with http protocol (from proxy-defaults)": {
|
2019-07-02 16:01:17 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
2020-02-06 15:52:25 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
|
|
|
},
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"router fails with tcp protocol": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
2020-02-06 15:52:25 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"other": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
ServiceSubset: "other",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"router fails without default protocol": {
|
2020-02-06 15:52:25 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"other": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
ServiceSubset: "other",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
|
|
|
/////////////////////////////////////////////////
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot remove default protocol after splitter created": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
2020-01-24 15:04:58 +00:00
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opDelete: configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot remove global default protocol after splitter created": {
|
2019-07-02 16:01:17 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
2020-02-06 15:52:25 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-02-06 15:52:25 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-02 16:01:17 +00:00
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
2020-02-06 15:52:25 +00:00
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opDelete: configentry.NewKindName(structs.ProxyDefaults, structs.ProxyConfigGlobal, nil),
|
2019-07-02 16:01:17 +00:00
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"can remove global default protocol after splitter created if service default overrides it": {
|
2019-07-02 16:01:17 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-02 16:01:17 +00:00
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
2020-01-24 15:04:58 +00:00
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opDelete: configentry.NewKindName(structs.ProxyDefaults, structs.ProxyConfigGlobal, nil),
|
2019-07-02 16:01:17 +00:00
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot change to tcp protocol after splitter created": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
2020-01-24 15:04:58 +00:00
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot remove default protocol after router created": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"other": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
2020-01-24 15:04:58 +00:00
|
|
|
ServiceSubset: "other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opDelete: configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot change to tcp protocol after router created": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"other": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Filter: "Service.Meta.version == other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
2020-01-24 15:04:58 +00:00
|
|
|
ServiceSubset: "other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "does not permit advanced routing or splitting behavior",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
|
|
|
/////////////////////////////////////////////////
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot split to a service using tcp": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "other",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90},
|
|
|
|
{Weight: 10, Service: "other"},
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "uses inconsistent protocols",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot route to a service using tcp": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "other",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "other",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "uses inconsistent protocols",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
|
|
|
/////////////////////////////////////////////////
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot failover to a service using a different protocol": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "other",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "other",
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "uses inconsistent protocols",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot redirect to a service using a different protocol": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "other",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: "uses inconsistent protocols",
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
|
|
|
/////////////////////////////////////////////////
|
2020-06-16 17:19:31 +00:00
|
|
|
"redirect to a subset that does exist is fine": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "other",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2019-07-01 20:23:36 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
ServiceSubset: "v1",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot redirect to a subset that does not exist": {
|
2019-07-01 20:23:36 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "other",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
ServiceSubset: "v1",
|
|
|
|
},
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
expectErr: `does not have a subset named "v1"`,
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2019-08-02 14:18:45 +00:00
|
|
|
/////////////////////////////////////////////////
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot introduce circular resolver redirect": {
|
2019-08-02 14:18:45 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "other",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "main",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
},
|
2019-08-02 14:18:45 +00:00
|
|
|
},
|
|
|
|
expectErr: `detected circular resolver redirect`,
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"cannot introduce circular split": {
|
2019-08-02 14:18:45 +00:00
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: "service-splitter",
|
|
|
|
Name: "other",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100, Service: "main"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
opAdd: &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: "service-splitter",
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100, Service: "other"},
|
|
|
|
},
|
2019-08-02 14:18:45 +00:00
|
|
|
},
|
|
|
|
expectErr: `detected circular reference`,
|
|
|
|
expectGraphErr: true,
|
|
|
|
},
|
2022-07-12 16:03:41 +00:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
"cannot peer export cross-dc redirect": {
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opAdd: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{{
|
|
|
|
Name: "main",
|
2022-10-04 18:46:15 +00:00
|
|
|
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
|
2022-07-12 16:03:41 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
expectErr: `contains cross-datacenter resolver redirect`,
|
|
|
|
},
|
|
|
|
"cannot peer export cross-dc redirect via wildcard": {
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opAdd: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{{
|
|
|
|
Name: "*",
|
2022-10-04 18:46:15 +00:00
|
|
|
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
|
2022-07-12 16:03:41 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
expectErr: `contains cross-datacenter resolver redirect`,
|
|
|
|
},
|
|
|
|
"cannot peer export cross-dc failover": {
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opAdd: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{{
|
|
|
|
Name: "main",
|
2022-10-04 18:46:15 +00:00
|
|
|
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
|
2022-07-12 16:03:41 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
expectErr: `contains cross-datacenter failover`,
|
|
|
|
},
|
|
|
|
"cannot peer export cross-dc failover via wildcard": {
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opAdd: &structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{{
|
|
|
|
Name: "*",
|
2022-10-04 18:46:15 +00:00
|
|
|
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
|
2022-07-12 16:03:41 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
expectErr: `contains cross-datacenter failover`,
|
|
|
|
},
|
2022-07-12 16:17:33 +00:00
|
|
|
"cannot redirect a peer exported tcp service": {
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ExportedServicesConfigEntry{
|
|
|
|
Name: "default",
|
|
|
|
Services: []structs.ExportedService{{
|
|
|
|
Name: "main",
|
2022-10-04 18:46:15 +00:00
|
|
|
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
|
2022-07-12 16:17:33 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opAdd: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectErr: `cannot introduce new discovery chain targets like`,
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2022-07-12 16:03:41 +00:00
|
|
|
run(t, tc)
|
2019-07-01 20:23:36 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_ReadDiscoveryChainConfigEntries_Overrides(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
entries []structs.ConfigEntry
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore []configentry.KindName
|
|
|
|
overrides map[configentry.KindName]structs.ConfigEntry
|
|
|
|
expectAfter []configentry.KindName
|
2019-07-01 20:23:36 +00:00
|
|
|
expectAfterErr string
|
2022-02-22 16:36:36 +00:00
|
|
|
checkAfter func(t *testing.T, entrySet *configentry.DiscoveryChainSet)
|
2019-07-01 20:23:36 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "mask service-defaults",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil): nil,
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
2019-07-01 20:23:36 +00:00
|
|
|
// nothing
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "edit service-defaults",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil): &structs.ServiceConfigEntry{
|
2019-07-01 20:23:36 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
checkAfter: func(t *testing.T, entrySet *configentry.DiscoveryChainSet) {
|
2020-01-24 15:04:58 +00:00
|
|
|
defaults := entrySet.GetService(structs.NewServiceID("main", nil))
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NotNil(t, defaults)
|
|
|
|
require.Equal(t, "grpc", defaults.Protocol)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: "mask service-router",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceRouter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceRouter, "main", nil): nil,
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "edit service-router",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {Filter: "Service.Meta.version == v1"},
|
|
|
|
"v2": {Filter: "Service.Meta.version == v2"},
|
|
|
|
"v3": {Filter: "Service.Meta.version == v3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/admin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
ServiceSubset: "v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceRouter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceRouter, "main", nil): &structs.ServiceRouterConfigEntry{
|
2019-07-01 20:23:36 +00:00
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "main",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/admin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
ServiceSubset: "v3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceRouter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
checkAfter: func(t *testing.T, entrySet *configentry.DiscoveryChainSet) {
|
2020-01-24 15:04:58 +00:00
|
|
|
router := entrySet.GetRouter(structs.NewServiceID("main", nil))
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NotNil(t, router)
|
|
|
|
require.Len(t, router.Routes, 1)
|
|
|
|
|
|
|
|
expect := structs.ServiceRoute{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/admin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
ServiceSubset: "v3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.Equal(t, expect, router.Routes[0])
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: "mask service-splitter",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceSplitter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceSplitter, "main", nil): nil,
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "edit service-splitter",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceSplitter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceSplitter, "main", nil): &structs.ServiceSplitterConfigEntry{
|
2019-07-01 20:23:36 +00:00
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 85, ServiceSubset: "v1"},
|
|
|
|
{Weight: 15, ServiceSubset: "v2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceDefaults, "main", nil),
|
|
|
|
configentry.NewKindName(structs.ServiceSplitter, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
checkAfter: func(t *testing.T, entrySet *configentry.DiscoveryChainSet) {
|
2020-01-24 15:04:58 +00:00
|
|
|
splitter := entrySet.GetSplitter(structs.NewServiceID("main", nil))
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NotNil(t, splitter)
|
|
|
|
require.Len(t, splitter.Splits, 2)
|
|
|
|
|
|
|
|
expect := []structs.ServiceSplit{
|
|
|
|
{Weight: 85, ServiceSubset: "v1"},
|
|
|
|
{Weight: 15, ServiceSubset: "v2"},
|
|
|
|
}
|
|
|
|
require.Equal(t, expect, splitter.Splits)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: "mask service-resolver",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil): nil,
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
2019-07-01 20:23:36 +00:00
|
|
|
// nothing
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "edit service-resolver",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectBefore: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
overrides: map[configentry.KindName]structs.ConfigEntry{
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil): &structs.ServiceResolverConfigEntry{
|
2019-07-01 20:23:36 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
expectAfter: []configentry.KindName{
|
|
|
|
configentry.NewKindName(structs.ServiceResolver, "main", nil),
|
2019-07-01 20:23:36 +00:00
|
|
|
},
|
2022-02-22 16:36:36 +00:00
|
|
|
checkAfter: func(t *testing.T, entrySet *configentry.DiscoveryChainSet) {
|
2020-01-24 15:04:58 +00:00
|
|
|
resolver := entrySet.GetResolver(structs.NewServiceID("main", nil))
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NotNil(t, resolver)
|
|
|
|
require.Equal(t, 33*time.Second, resolver.ConnectTimeout)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2019-07-01 20:23:36 +00:00
|
|
|
for _, entry := range tc.entries {
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, entry))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("without override", func(t *testing.T) {
|
2020-01-24 15:04:58 +00:00
|
|
|
_, entrySet, err := s.readDiscoveryChainConfigEntries(nil, "main", nil, nil)
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
got := entrySetToKindNames(entrySet)
|
|
|
|
require.ElementsMatch(t, tc.expectBefore, got)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with override", func(t *testing.T) {
|
2020-01-24 15:04:58 +00:00
|
|
|
_, entrySet, err := s.readDiscoveryChainConfigEntries(nil, "main", tc.overrides, nil)
|
2019-07-01 20:23:36 +00:00
|
|
|
|
|
|
|
if tc.expectAfterErr != "" {
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), tc.expectAfterErr)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
got := entrySetToKindNames(entrySet)
|
|
|
|
require.ElementsMatch(t, tc.expectAfter, got)
|
|
|
|
|
|
|
|
if tc.checkAfter != nil {
|
|
|
|
tc.checkAfter(t, entrySet)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:36:36 +00:00
|
|
|
func entrySetToKindNames(entrySet *configentry.DiscoveryChainSet) []configentry.KindName {
|
|
|
|
var out []configentry.KindName
|
2019-07-01 20:23:36 +00:00
|
|
|
for _, entry := range entrySet.Routers {
|
2022-02-22 16:36:36 +00:00
|
|
|
out = append(out, configentry.NewKindName(
|
2020-09-02 15:47:19 +00:00
|
|
|
entry.Kind,
|
|
|
|
entry.Name,
|
|
|
|
&entry.EnterpriseMeta,
|
|
|
|
))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
|
|
|
for _, entry := range entrySet.Splitters {
|
2022-02-22 16:36:36 +00:00
|
|
|
out = append(out, configentry.NewKindName(
|
2020-09-02 15:47:19 +00:00
|
|
|
entry.Kind,
|
|
|
|
entry.Name,
|
|
|
|
&entry.EnterpriseMeta,
|
|
|
|
))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
|
|
|
for _, entry := range entrySet.Resolvers {
|
2022-02-22 16:36:36 +00:00
|
|
|
out = append(out, configentry.NewKindName(
|
2020-09-02 15:47:19 +00:00
|
|
|
entry.Kind,
|
|
|
|
entry.Name,
|
|
|
|
&entry.EnterpriseMeta,
|
|
|
|
))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
|
|
|
for _, entry := range entrySet.Services {
|
2022-02-22 16:36:36 +00:00
|
|
|
out = append(out, configentry.NewKindName(
|
2020-09-02 15:47:19 +00:00
|
|
|
entry.Kind,
|
|
|
|
entry.Name,
|
|
|
|
&entry.EnterpriseMeta,
|
|
|
|
))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
2021-11-13 01:57:05 +00:00
|
|
|
for _, entry := range entrySet.ProxyDefaults {
|
2022-02-22 16:36:36 +00:00
|
|
|
out = append(out, configentry.NewKindName(
|
2021-11-13 01:57:05 +00:00
|
|
|
entry.Kind,
|
|
|
|
entry.Name,
|
|
|
|
&entry.EnterpriseMeta,
|
|
|
|
))
|
|
|
|
}
|
2019-07-01 20:23:36 +00:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_ReadDiscoveryChainConfigEntries_SubsetSplit(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2019-07-01 20:23:36 +00:00
|
|
|
|
|
|
|
entries := []structs.ConfigEntry{
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "main",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "main",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2019-07-01 20:23:36 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2019-07-01 20:23:36 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "main",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, ServiceSubset: "v1"},
|
|
|
|
{Weight: 10, ServiceSubset: "v2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range entries {
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, entry))
|
2019-07-01 20:23:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 22:05:09 +00:00
|
|
|
_, entrySet, err := s.readDiscoveryChainConfigEntries(nil, "main", nil, nil)
|
2019-07-01 20:23:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, entrySet.Routers, 0)
|
|
|
|
require.Len(t, entrySet.Splitters, 1)
|
|
|
|
require.Len(t, entrySet.Resolvers, 1)
|
|
|
|
require.Len(t, entrySet.Services, 1)
|
|
|
|
}
|
2020-04-16 21:00:48 +00:00
|
|
|
|
2020-10-06 18:24:05 +00:00
|
|
|
// TODO(rb): add ServiceIntentions tests
|
|
|
|
|
2020-04-16 21:00:48 +00:00
|
|
|
func TestStore_ValidateGatewayNamesCannotBeShared(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-04-16 21:00:48 +00:00
|
|
|
|
|
|
|
ingress := &structs.IngressGatewayConfigEntry{
|
|
|
|
Kind: structs.IngressGateway,
|
|
|
|
Name: "gateway",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, ingress))
|
2020-04-16 21:00:48 +00:00
|
|
|
|
|
|
|
terminating := &structs.TerminatingGatewayConfigEntry{
|
|
|
|
Kind: structs.TerminatingGateway,
|
|
|
|
Name: "gateway",
|
|
|
|
}
|
|
|
|
// Cannot have 2 gateways with same service name
|
2021-02-03 23:10:38 +00:00
|
|
|
require.Error(t, s.EnsureConfigEntry(1, terminating))
|
2020-04-16 21:00:48 +00:00
|
|
|
|
|
|
|
ingress = &structs.IngressGatewayConfigEntry{
|
|
|
|
Kind: structs.IngressGateway,
|
|
|
|
Name: "gateway",
|
|
|
|
Listeners: []structs.IngressListener{
|
|
|
|
{Port: 8080},
|
|
|
|
},
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(2, ingress))
|
2020-04-16 21:00:48 +00:00
|
|
|
require.NoError(t, s.DeleteConfigEntry(3, structs.IngressGateway, "gateway", nil))
|
|
|
|
|
|
|
|
// Adding the terminating gateway with same name should now work
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(4, terminating))
|
2020-04-16 21:00:48 +00:00
|
|
|
|
|
|
|
// Cannot have 2 gateways with same service name
|
2021-02-03 23:10:38 +00:00
|
|
|
require.Error(t, s.EnsureConfigEntry(5, ingress))
|
2020-04-16 21:00:48 +00:00
|
|
|
}
|
2020-05-06 21:09:24 +00:00
|
|
|
|
|
|
|
func TestStore_ValidateIngressGatewayErrorOnMismatchedProtocols(t *testing.T) {
|
2020-08-12 16:19:20 +00:00
|
|
|
newIngress := func(protocol, name string) *structs.IngressGatewayConfigEntry {
|
|
|
|
return &structs.IngressGatewayConfigEntry{
|
|
|
|
Kind: structs.IngressGateway,
|
|
|
|
Name: "gateway",
|
|
|
|
Listeners: []structs.IngressListener{
|
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
Protocol: protocol,
|
|
|
|
Services: []structs.IngressService{
|
|
|
|
{Name: name},
|
|
|
|
},
|
2020-05-06 21:09:24 +00:00
|
|
|
},
|
|
|
|
},
|
2020-08-12 16:19:20 +00:00
|
|
|
}
|
2020-05-06 21:09:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("http ingress fails with http upstream later changed to tcp", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// First set the target service as http
|
|
|
|
expected := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "http",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, expected))
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// Next configure http ingress to route to the http service
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, newIngress("http", "web")))
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
t.Run("via modification", func(t *testing.T) {
|
|
|
|
// Now redefine the target service as tcp
|
|
|
|
expected = &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "tcp",
|
|
|
|
}
|
|
|
|
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(2, expected)
|
2020-08-12 16:19:20 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), `has protocol "tcp"`)
|
|
|
|
})
|
|
|
|
t.Run("via deletion", func(t *testing.T) {
|
|
|
|
// This will fall back to the default tcp.
|
|
|
|
err := s.DeleteConfigEntry(2, structs.ServiceDefaults, "web", nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), `has protocol "tcp"`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tcp ingress ok with tcp upstream (defaulted) later changed to http", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// First configure tcp ingress to route to a defaulted tcp service
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, newIngress("tcp", "web")))
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// Now redefine the target service as http
|
|
|
|
expected := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "http",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, expected))
|
2020-08-12 16:19:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tcp ingress fails with tcp upstream (defaulted) later changed to http", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// First configure tcp ingress to route to a defaulted tcp service
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, newIngress("tcp", "web")))
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
// Now redefine the target service as http
|
|
|
|
expected := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "http",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, expected))
|
2020-08-12 16:19:20 +00:00
|
|
|
|
|
|
|
t.Run("and a router defined", func(t *testing.T) {
|
|
|
|
// This part should fail.
|
|
|
|
expected2 := &structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "web",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(2, expected2)
|
2020-08-12 16:19:20 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), `has protocol "http"`)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("and a splitter defined", func(t *testing.T) {
|
|
|
|
// This part should fail.
|
|
|
|
expected2 := &structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "web",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 100},
|
|
|
|
},
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(2, expected2)
|
2020-08-12 16:19:20 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), `has protocol "http"`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("http ingress fails with tcp upstream (defaulted)", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(0, newIngress("http", "web"))
|
2020-05-06 21:09:24 +00:00
|
|
|
require.Error(t, err)
|
2020-05-08 18:24:33 +00:00
|
|
|
require.Contains(t, err.Error(), `has protocol "tcp"`)
|
2020-05-06 21:09:24 +00:00
|
|
|
})
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("http ingress fails with http2 upstream (via proxy-defaults)", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-05-06 21:09:24 +00:00
|
|
|
expected := &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: "global",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http2",
|
|
|
|
},
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(0, expected))
|
2020-05-06 21:09:24 +00:00
|
|
|
|
2021-02-03 23:10:38 +00:00
|
|
|
err := s.EnsureConfigEntry(1, newIngress("http", "web"))
|
2020-05-06 21:09:24 +00:00
|
|
|
require.Error(t, err)
|
2020-05-08 18:24:33 +00:00
|
|
|
require.Contains(t, err.Error(), `has protocol "http2"`)
|
2020-05-06 21:09:24 +00:00
|
|
|
})
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("http ingress fails with grpc upstream (via service-defaults)", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-05-06 21:09:24 +00:00
|
|
|
expected := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "grpc",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, expected))
|
|
|
|
err := s.EnsureConfigEntry(2, newIngress("http", "web"))
|
2020-05-06 21:09:24 +00:00
|
|
|
require.Error(t, err)
|
2020-05-08 18:24:33 +00:00
|
|
|
require.Contains(t, err.Error(), `has protocol "grpc"`)
|
2020-05-06 21:09:24 +00:00
|
|
|
})
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("http ingress ok with http upstream (via service-defaults)", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2020-05-06 21:09:24 +00:00
|
|
|
expected := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "http",
|
|
|
|
}
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(2, expected))
|
|
|
|
require.NoError(t, s.EnsureConfigEntry(3, newIngress("http", "web")))
|
2020-05-06 21:09:24 +00:00
|
|
|
})
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("http ingress ignores wildcard specifier", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(4, newIngress("http", "*")))
|
2020-05-06 21:09:24 +00:00
|
|
|
})
|
|
|
|
|
2020-08-12 16:19:20 +00:00
|
|
|
t.Run("deleting ingress config entry ok", func(t *testing.T) {
|
2020-10-06 18:24:05 +00:00
|
|
|
s := testConfigStateStore(t)
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(1, newIngress("tcp", "web")))
|
2020-05-06 21:09:24 +00:00
|
|
|
require.NoError(t, s.DeleteConfigEntry(5, structs.IngressGateway, "gateway", nil))
|
|
|
|
})
|
|
|
|
}
|
2020-09-22 22:05:09 +00:00
|
|
|
|
|
|
|
func TestSourcesForTarget(t *testing.T) {
|
2021-07-22 18:20:45 +00:00
|
|
|
defaultMeta := *structs.DefaultEnterpriseMetaInDefaultPartition()
|
2020-09-22 22:05:09 +00:00
|
|
|
|
|
|
|
type expect struct {
|
2020-10-02 00:10:49 +00:00
|
|
|
idx uint64
|
|
|
|
names []structs.ServiceName
|
2020-09-22 22:05:09 +00:00
|
|
|
}
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
entries []structs.ConfigEntry
|
|
|
|
expect expect
|
|
|
|
}{
|
2020-10-02 00:10:49 +00:00
|
|
|
{
|
|
|
|
name: "no relevant config entries",
|
|
|
|
entries: []structs.ConfigEntry{},
|
|
|
|
expect: expect{
|
|
|
|
idx: 1,
|
|
|
|
names: []structs.ServiceName{
|
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-22 22:05:09 +00:00
|
|
|
{
|
|
|
|
name: "from route match",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "web",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from redirect",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from failover",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "sink",
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from splitter",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "web",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, Service: "web"},
|
|
|
|
{Weight: 10, Service: "sink"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "chained route redirect",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "source",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/route",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "routed",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "routed",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 3,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "source", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "routed", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "kitchen sink with multiple services referencing sink directly",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "routed",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "redirected",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "failed-over",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "sink",
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "split",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, Service: "no-op"},
|
|
|
|
{Weight: 10, Service: "sink"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "unrelated",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, Service: "zip"},
|
|
|
|
{Weight: 10, Service: "zop"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 6,
|
2020-10-02 00:10:49 +00:00
|
|
|
names: []structs.ServiceName{
|
2020-09-22 22:05:09 +00:00
|
|
|
{Name: "split", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "failed-over", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "redirected", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "routed", EnterpriseMeta: defaultMeta},
|
2020-10-02 00:10:49 +00:00
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
2020-09-22 22:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
s := testStateStore(t)
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
|
|
|
ca := &structs.CAConfiguration{
|
|
|
|
Provider: "consul",
|
|
|
|
}
|
|
|
|
err := s.CASetConfig(0, ca)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var i uint64 = 1
|
|
|
|
for _, entry := range tc.entries {
|
|
|
|
require.NoError(t, entry.Normalize())
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(i, entry))
|
2020-09-22 22:05:09 +00:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := s.db.ReadTxn()
|
|
|
|
defer tx.Abort()
|
|
|
|
|
2021-07-22 18:20:45 +00:00
|
|
|
sn := structs.NewServiceName("sink", structs.DefaultEnterpriseMetaInDefaultPartition())
|
2020-10-02 00:10:49 +00:00
|
|
|
idx, names, err := s.discoveryChainSourcesTxn(tx, ws, "dc1", sn)
|
2020-09-22 22:05:09 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, tc.expect.idx, idx)
|
2020-10-02 00:10:49 +00:00
|
|
|
require.ElementsMatch(t, tc.expect.names, names)
|
2020-09-22 22:05:09 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 20:24:42 +00:00
|
|
|
|
|
|
|
func TestTargetsForSource(t *testing.T) {
|
2021-07-22 18:20:45 +00:00
|
|
|
defaultMeta := *structs.DefaultEnterpriseMetaInDefaultPartition()
|
2020-09-27 20:24:42 +00:00
|
|
|
|
|
|
|
type expect struct {
|
|
|
|
idx uint64
|
|
|
|
ids []structs.ServiceName
|
|
|
|
}
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
entries []structs.ConfigEntry
|
|
|
|
expect expect
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "from route match",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "web",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
|
|
|
ids: []structs.ServiceName{
|
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from redirect",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
|
|
|
ids: []structs.ServiceName{
|
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from failover",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "remote-web",
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
|
|
|
ids: []structs.ServiceName{
|
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "from splitter",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "web",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 90, Service: "web"},
|
|
|
|
{Weight: 10, Service: "sink"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 2,
|
|
|
|
ids: []structs.ServiceName{
|
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "chained route redirect",
|
|
|
|
entries: []structs.ConfigEntry{
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "web",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/route",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "routed",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "routed",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "sink",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expect: expect{
|
|
|
|
idx: 3,
|
|
|
|
ids: []structs.ServiceName{
|
|
|
|
{Name: "web", EnterpriseMeta: defaultMeta},
|
|
|
|
{Name: "sink", EnterpriseMeta: defaultMeta},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
s := testStateStore(t)
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
|
|
|
ca := &structs.CAConfiguration{
|
|
|
|
Provider: "consul",
|
|
|
|
}
|
|
|
|
err := s.CASetConfig(0, ca)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var i uint64 = 1
|
|
|
|
for _, entry := range tc.entries {
|
|
|
|
require.NoError(t, entry.Normalize())
|
2021-02-03 23:10:38 +00:00
|
|
|
require.NoError(t, s.EnsureConfigEntry(i, entry))
|
2020-09-27 20:24:42 +00:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := s.db.ReadTxn()
|
|
|
|
defer tx.Abort()
|
|
|
|
|
2020-10-02 00:10:49 +00:00
|
|
|
idx, ids, err := s.discoveryChainTargetsTxn(tx, ws, "dc1", "web", nil)
|
2020-09-27 20:24:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, tc.expect.idx, idx)
|
|
|
|
require.ElementsMatch(t, tc.expect.ids, ids)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-10-06 22:09:13 +00:00
|
|
|
|
|
|
|
func TestStore_ValidateServiceIntentionsErrorOnIncompatibleProtocols(t *testing.T) {
|
|
|
|
l7perms := []*structs.IntentionPermission{
|
|
|
|
{
|
|
|
|
Action: structs.IntentionActionAllow,
|
|
|
|
HTTP: &structs.IntentionHTTPPermission{
|
|
|
|
PathPrefix: "/v2/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceDefaults := func(service, protocol string) *structs.ServiceConfigEntry {
|
|
|
|
return &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: service,
|
|
|
|
Protocol: protocol,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyDefaults := func(protocol string) *structs.ProxyConfigEntry {
|
|
|
|
return &structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": protocol,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type operation struct {
|
|
|
|
entry structs.ConfigEntry
|
|
|
|
deletion bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
ops []operation
|
|
|
|
expectLastErr string
|
|
|
|
}
|
|
|
|
|
|
|
|
cases := map[string]testcase{
|
|
|
|
"L4 intention cannot upgrade to L7 when tcp": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as tcp
|
|
|
|
entry: serviceDefaults("api", "tcp"),
|
|
|
|
},
|
|
|
|
{ // create an L4 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Action: structs.IntentionActionAllow},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // Should fail if converted to L7
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectLastErr: `has protocol "tcp"`,
|
|
|
|
},
|
|
|
|
"L4 intention can upgrade to L7 when made http via service-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as tcp
|
|
|
|
entry: serviceDefaults("api", "tcp"),
|
|
|
|
},
|
|
|
|
{ // create an L4 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Action: structs.IntentionActionAllow},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: serviceDefaults("api", "http"),
|
|
|
|
},
|
|
|
|
{ // Should succeed if converted to L7
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"L4 intention can upgrade to L7 when made http via proxy-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as tcp
|
|
|
|
entry: proxyDefaults("tcp"),
|
|
|
|
},
|
|
|
|
{ // create an L4 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Action: structs.IntentionActionAllow},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: proxyDefaults("http"),
|
|
|
|
},
|
|
|
|
{ // Should succeed if converted to L7
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"L7 intention cannot have protocol downgraded to tcp via modification via service-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: serviceDefaults("api", "http"),
|
|
|
|
},
|
|
|
|
{ // create an L7 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // setting the target service as tcp should fail
|
|
|
|
entry: serviceDefaults("api", "tcp"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectLastErr: `has protocol "tcp"`,
|
|
|
|
},
|
|
|
|
"L7 intention cannot have protocol downgraded to tcp via modification via proxy-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: proxyDefaults("http"),
|
|
|
|
},
|
|
|
|
{ // create an L7 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // setting the target service as tcp should fail
|
|
|
|
entry: proxyDefaults("tcp"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectLastErr: `has protocol "tcp"`,
|
|
|
|
},
|
|
|
|
"L7 intention cannot have protocol downgraded to tcp via deletion of service-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: serviceDefaults("api", "http"),
|
|
|
|
},
|
|
|
|
{ // create an L7 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // setting the target service as tcp should fail
|
|
|
|
entry: serviceDefaults("api", "tcp"),
|
|
|
|
deletion: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectLastErr: `has protocol "tcp"`,
|
|
|
|
},
|
|
|
|
"L7 intention cannot have protocol downgraded to tcp via deletion of proxy-defaults": {
|
|
|
|
ops: []operation{
|
|
|
|
{ // set the target service as http
|
|
|
|
entry: proxyDefaults("http"),
|
|
|
|
},
|
|
|
|
{ // create an L7 intention
|
|
|
|
entry: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
|
|
|
Name: "api",
|
|
|
|
Sources: []*structs.SourceIntention{
|
|
|
|
{Name: "web", Permissions: l7perms},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ // setting the target service as tcp should fail
|
|
|
|
entry: proxyDefaults("tcp"),
|
|
|
|
deletion: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectLastErr: `has protocol "tcp"`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
s := testStateStore(t)
|
|
|
|
|
|
|
|
var nextIndex = uint64(1)
|
|
|
|
|
|
|
|
for i, op := range tc.ops {
|
|
|
|
isLast := (i == len(tc.ops)-1)
|
|
|
|
|
|
|
|
var err error
|
|
|
|
if op.deletion {
|
|
|
|
err = s.DeleteConfigEntry(nextIndex, op.entry.GetKind(), op.entry.GetName(), nil)
|
|
|
|
} else {
|
2021-02-03 23:10:38 +00:00
|
|
|
err = s.EnsureConfigEntry(nextIndex, op.entry)
|
2020-10-06 22:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if isLast && tc.expectLastErr != "" {
|
|
|
|
testutil.RequireErrorContains(t, err, `has protocol "tcp"`)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|