Preserve custom etcd prefix compatibility for etcd3

This commit is contained in:
Jordan Liggitt 2017-03-03 17:47:57 -05:00
parent 20c13c1564
commit 6853e4d71e
No known key found for this signature in database
GPG Key ID: 24E7ADF9A3B42012
3 changed files with 41 additions and 2 deletions

View File

@ -674,3 +674,22 @@ func TestDeleteWithRetry(t *testing.T) {
t.Errorf("Expect an NotFound error, got %v", err)
}
}
func TestPrefix(t *testing.T) {
scheme, codecs := testScheme(t)
codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion)
server := etcdtesting.NewEtcdTestClientServer(t)
defer server.Terminate(t)
testcases := map[string]string{
"custom/prefix": "/custom/prefix",
"/custom//prefix//": "/custom/prefix",
"/registry": "/registry",
}
for configuredPrefix, effectivePrefix := range testcases {
helper := newEtcdHelper(server.Client, scheme, codec, configuredPrefix)
if helper.pathPrefix != effectivePrefix {
t.Errorf("configured prefix of %s, expected effective prefix of %s, got %s", configuredPrefix, effectivePrefix, helper.pathPrefix)
}
}
}

View File

@ -102,7 +102,10 @@ func newStore(c *clientv3.Client, quorumRead bool, codec runtime.Codec, prefix s
codec: codec,
versioner: versioner,
transformer: transformer,
pathPrefix: prefix,
// for compatibility with etcd2 impl.
// no-op for default prefix of '/registry'.
// keeps compatibility with etcd2 impl for custom prefixes that don't start with '/'
pathPrefix: path.Join("/", prefix),
watcher: newWatcher(c, codec, versioner, transformer),
}
if !quorumRead {

View File

@ -688,3 +688,20 @@ func testPropogateStore(ctx context.Context, t *testing.T, store *store, obj *ex
}
return key, setOutput
}
func TestPrefix(t *testing.T) {
codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion)
cluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
transformer := prefixTransformer{prefix: []byte("test!")}
testcases := map[string]string{
"custom/prefix": "/custom/prefix",
"/custom//prefix//": "/custom/prefix",
"/registry": "/registry",
}
for configuredPrefix, effectivePrefix := range testcases {
store := newStore(cluster.RandClient(), false, codec, configuredPrefix, transformer)
if store.pathPrefix != effectivePrefix {
t.Errorf("configured prefix of %s, expected effective prefix of %s, got %s", configuredPrefix, effectivePrefix, store.pathPrefix)
}
}
}