forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_daemon.go
47 lines (39 loc) · 1.26 KB
/
mysql_daemon.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
44
45
46
47
// Copyright 2012, 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 mysqlctl
import (
"fmt"
)
// MysqlDaemon is the interface we use for abstracting Mysqld.
type MysqlDaemon interface {
// GetMasterAddr returns the mysql master address, as shown by
// 'show slave status'.
GetMasterAddr() (string, error)
// GetMysqlPort returns the current port mysql is listening on.
GetMysqlPort() (int, error)
}
// FakeMysqlDaemon implements MysqlDaemon and allows the user to fake
// everything.
type FakeMysqlDaemon struct {
// will be returned by GetMasterAddr(). Set to "" to return
// ErrNotSlave, or to "ERROR" to return an error.
MasterAddr string
// will be returned by GetMysqlPort(). Set to -1 to return an error.
MysqlPort int
}
func (fmd *FakeMysqlDaemon) GetMasterAddr() (string, error) {
if fmd.MasterAddr == "" {
return "", ErrNotSlave
}
if fmd.MasterAddr == "ERROR" {
return "", fmt.Errorf("FakeMysqlDaemon.GetMasterAddr returns an error")
}
return fmd.MasterAddr, nil
}
func (fmd *FakeMysqlDaemon) GetMysqlPort() (int, error) {
if fmd.MysqlPort == -1 {
return 0, fmt.Errorf("FakeMysqlDaemon.GetMysqlPort returns an error")
}
return fmd.MysqlPort, nil
}