Skip to content

Commit

Permalink
pool: implemented Role Stringer interface
Browse files Browse the repository at this point in the history
implemented Role Stringer interface for human-readable printing
  • Loading branch information
Maksim Konovalov authored and oleg-jukovec committed Sep 16, 2024
1 parent f1d88dc commit 0ccdee2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
also added logs for error case of `ConnectionPool.tryConnect()` calls in
`ConnectionPool.controller()` and `ConnectionPool.reconnect()`
- Methods that are implemented but not included in the pooler interface (#395).
- Implemented stringer methods for pool.Role (#405).

### Changed

Expand Down
10 changes: 7 additions & 3 deletions pool/const.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate stringer -type Role -linecomment
package pool

/*
Expand Down Expand Up @@ -31,7 +32,10 @@ const (
type Role uint32

const (
UnknownRole Role = iota // A connection pool failed to discover mode of the instance.
MasterRole // The instance is read-write mode.
ReplicaRole // The instance is in read-only mode.
// UnknownRole - the connection pool was unable to detect the instance mode.
UnknownRole Role = iota // unknown
// MasterRole - the instance is in read-write mode.
MasterRole // master
// ReplicaRole - the instance is in read-only mode.
ReplicaRole // replica
)
13 changes: 13 additions & 0 deletions pool/const_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pool

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRole_String(t *testing.T) {
require.Equal(t, "unknown", UnknownRole.String())
require.Equal(t, "master", MasterRole.String())
require.Equal(t, "replica", ReplicaRole.String())
}
25 changes: 25 additions & 0 deletions pool/role_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ccdee2

Please sign in to comment.