File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
9
9
## [ Unreleased]
10
10
11
11
### Added
12
+ - Implemented Stringer interface for pool.Role type (#405 ).
12
13
- Add err log to ` ConnectionPool.Add() ` in case, when unable to establish
13
14
connection and ctx is not canceled;
14
15
also added logs for error case of ` ConnectionPool.tryConnect() ` calls in
Original file line number Diff line number Diff line change @@ -35,3 +35,14 @@ const (
35
35
MasterRole // The instance is read-write mode.
36
36
ReplicaRole // The instance is in read-only mode.
37
37
)
38
+
39
+ var role2String = map [Role ]string {
40
+ UnknownRole : "unknown" ,
41
+ MasterRole : "master" ,
42
+ ReplicaRole : "replica" ,
43
+ }
44
+
45
+ // String is implementation of the Stringer interface for human readability when printing a value
46
+ func (r Role ) String () string {
47
+ return role2String [r ]
48
+ }
Original file line number Diff line number Diff line change
1
+ package pool
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+
7
+ "github.com/stretchr/testify/require"
8
+ )
9
+
10
+ func TestRole_String (t * testing.T ) {
11
+ // Checking that print is non-number(len = 1 ) Role
12
+ require .True (t , len (fmt .Sprintf ("%v" , UnknownRole )) > 1 )
13
+ require .True (t , len (fmt .Sprintf ("%v" , MasterRole )) > 1 )
14
+ require .True (t , len (fmt .Sprintf ("%v" , ReplicaRole )) > 1 )
15
+ }
You can’t perform that action at this time.
0 commit comments