forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callerid.go
43 lines (35 loc) · 1.25 KB
/
callerid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goclienttest
import (
"encoding/json"
"strings"
"testing"
"github.com/youtube/vitess/go/cmd/vtgateclienttest/services"
"github.com/youtube/vitess/go/vt/callerid"
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
"golang.org/x/net/context"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
)
// testCallerID adds a caller ID to a context, and makes sure the server
// gets it.
func testCallerID(t *testing.T, conn *vtgateconn.VTGateConn) {
t.Log("testCallerID")
ctx := context.Background()
callerID := callerid.NewEffectiveCallerID("test_principal", "test_component", "test_subcomponent")
ctx = callerid.NewContext(ctx, callerID, nil)
data, err := json.Marshal(callerID)
if err != nil {
t.Errorf("failed to marshal callerid: %v", err)
return
}
query := services.CallerIDPrefix + string(data)
// test Execute forwards the callerID
if _, err := conn.Execute(ctx, query, nil, topodatapb.TabletType_MASTER); err != nil {
if !strings.Contains(err.Error(), "SUCCESS: ") {
t.Errorf("failed to pass callerid: %v", err)
}
}
// FIXME(alainjobart) add all function calls
}