Skip to content

Commit f07c85d

Browse files
author
Maksim Konovalov
committed
pool: implemented Role Stringer interface
implemented Role Stringer interface for human-readable printing
1 parent f1d88dc commit f07c85d

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1414
also added logs for error case of `ConnectionPool.tryConnect()` calls in
1515
`ConnectionPool.controller()` and `ConnectionPool.reconnect()`
1616
- Methods that are implemented but not included in the pooler interface (#395).
17-
17+
- Implemented stringer methods for pool.Role (#405).
1818
### Changed
1919

2020
### Fixed

pool/const.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:generate stringer -type Role -linecomment
12
package pool
23

34
/*
@@ -31,7 +32,10 @@ const (
3132
type Role uint32
3233

3334
const (
34-
UnknownRole Role = iota // A connection pool failed to discover mode of the instance.
35-
MasterRole // The instance is read-write mode.
36-
ReplicaRole // The instance is in read-only mode.
35+
// UnknownRole - value when the connection pool was unable to detect the instance mode.
36+
UnknownRole Role = iota // unknown
37+
// MasterRole - the instance is read-write mode.
38+
MasterRole // master
39+
// ReplicaRole - the instance is in read-only mode.
40+
ReplicaRole // replica
3741
)

pool/const_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package pool
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestRole_String(t *testing.T) {
10+
require.Equal(t, "unknown", UnknownRole)
11+
require.Equal(t, "master", MasterRole)
12+
require.Equal(t, "replica", ReplicaRole)
13+
}

pool/role_string.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)