MCPcopy
hub / github.com/etcd-io/etcd / TestMetadataWithRequireLeader

Function TestMetadataWithRequireLeader

client/v3/ctx_test.go:29–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestMetadataWithRequireLeader(t *testing.T) {
30 ctx := context.TODO()
31 _, ok := metadata.FromOutgoingContext(ctx)
32 require.Falsef(t, ok, "expected no outgoing metadata ctx key")
33
34 // add a conflicting key with some other value
35 md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, "invalid")
36 // add a key, and expect not be overwritten
37 md.Set("hello", "1", "2")
38 ctx = metadata.NewOutgoingContext(ctx, md)
39
40 // expect overwrites but still keep other keys
41 ctx = WithRequireLeader(ctx)
42 md, ok = metadata.FromOutgoingContext(ctx)
43 require.Truef(t, ok, "expected outgoing metadata ctx key")
44 ss := md.Get(rpctypes.MetadataRequireLeaderKey)
45 require.Truef(t, reflect.DeepEqual(ss, []string{rpctypes.MetadataHasLeader}), "unexpected metadata for %q %v", rpctypes.MetadataRequireLeaderKey, ss)
46 ss = md.Get("hello")
47 require.Truef(t, reflect.DeepEqual(ss, []string{"1", "2"}), "unexpected metadata for 'hello' %v", ss)
48}
49
50func TestMetadataWithClientAPIVersion(t *testing.T) {
51 ctx := withVersion(WithRequireLeader(context.TODO()))

Callers

nothing calls this directly

Calls 3

WithRequireLeaderFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…