Preserve custom etcd prefix compatibility for etcd3
This commit is contained in:
		@@ -674,3 +674,22 @@ func TestDeleteWithRetry(t *testing.T) {
 | 
				
			|||||||
		t.Errorf("Expect an NotFound error, got %v", err)
 | 
							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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -102,8 +102,11 @@ func newStore(c *clientv3.Client, quorumRead bool, codec runtime.Codec, prefix s
 | 
				
			|||||||
		codec:       codec,
 | 
							codec:       codec,
 | 
				
			||||||
		versioner:   versioner,
 | 
							versioner:   versioner,
 | 
				
			||||||
		transformer: transformer,
 | 
							transformer: transformer,
 | 
				
			||||||
		pathPrefix:  prefix,
 | 
							// for compatibility with etcd2 impl.
 | 
				
			||||||
		watcher:     newWatcher(c, codec, versioner, transformer),
 | 
							// 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 {
 | 
						if !quorumRead {
 | 
				
			||||||
		// In case of non-quorum reads, we can set WithSerializable()
 | 
							// In case of non-quorum reads, we can set WithSerializable()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -688,3 +688,20 @@ func testPropogateStore(ctx context.Context, t *testing.T, store *store, obj *ex
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return key, setOutput
 | 
						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)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user