add a string representation for the perspective

This commit is contained in:
Marten Seemann
2018-02-01 12:59:24 +08:00
parent d9d384b6ed
commit 2ec147ccfa
2 changed files with 25 additions and 0 deletions

View File

@@ -8,3 +8,14 @@ const (
PerspectiveServer Perspective = 1
PerspectiveClient Perspective = 2
)
func (p Perspective) String() string {
switch p {
case PerspectiveServer:
return "Server"
case PerspectiveClient:
return "Client"
default:
return "invalid perspective"
}
}

View File

@@ -0,0 +1,14 @@
package protocol
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Perspective", func() {
It("has a string representation", func() {
Expect(PerspectiveClient.String()).To(Equal("Client"))
Expect(PerspectiveServer.String()).To(Equal("Server"))
Expect(Perspective(0).String()).To(Equal("invalid perspective"))
})
})