Move client server to write tests, added parameters to client.

This commit is contained in:
David Vennik
2022-03-29 12:15:23 +03:00
parent 6b4eded279
commit c9219a1715
9 changed files with 25 additions and 11 deletions

View File

@@ -12,7 +12,10 @@ var (
serverAddr = flag.String("a", defaultAddr, serverAddr = flag.String("a", defaultAddr,
"The server address for basedcli to connect to", "The server address for basedcli to connect to",
) )
hexInput = flag.String("h", "", "hex string to convert to based32 encoding") encode = flag.String("e", "", "hex string to convert to based32 encoding")
decode = flag.String("d", "",
"based32 encoded string to convert back to hex",
)
) )
func main() { func main() {
@@ -25,4 +28,5 @@ func main() {
"run with argument -h to print command line options", "run with argument -h to print command line options",
) )
} }
} }

View File

@@ -4,8 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/cybriq/interrupt" "github.com/cybriq/interrupt"
"github.com/cybriq/qu" "github.com/quanterall/kitchensink/pkg/grpc/server"
"github.com/quanterall/kitchensink/pkg/server"
"net" "net"
"os" "os"
) )
@@ -17,7 +16,7 @@ var serverAddr = flag.String("a", defaultAddr,
"- omit host to bind to all network interfaces", "- omit host to bind to all network interfaces",
) )
var killAll = qu.T() var killAll = make(chan struct{})
func main() { func main() {
@@ -42,8 +41,6 @@ func main() {
os.Exit(1) os.Exit(1)
} }
log.Println(addr)
svc := server.New(addr, 8) svc := server.New(addr, 8)
// interrupt is a library that allows the proper handling of OS interrupt // interrupt is a library that allows the proper handling of OS interrupt
@@ -51,6 +48,12 @@ func main() {
// properly closed and all pending writes are completed. // properly closed and all pending writes are completed.
interrupt.AddHandler(func() { interrupt.AddHandler(func() {
// Most of the time the shell spits out a `^C` when the user hits
// ctrl-c, the standard interrupt (cancel) key for a terminal. This adds
// a newline so our logs don't get indented with an ugly prefix making
// them less readable.
_, _ = fmt.Fprintln(os.Stderr)
// In this case, we are just ending the process, after the select block // In this case, we are just ending the process, after the select block
// below falls through when the channel is closed, the execution of the // below falls through when the channel is closed, the execution of the
// application terminates. // application terminates.
@@ -69,9 +72,9 @@ func main() {
// qu library makes it easier to debug the channels when run control // qu library makes it easier to debug the channels when run control
// bugs appear, you can print the information about the state of the // bugs appear, you can print the information about the state of the
// channels that are open and where in the code they are waiting. // channels that are open and where in the code they are waiting.
_, _ = fmt.Fprintln(os.Stderr)
log.Println("Shutting down basedd microservice") log.Println("Shutting down basedd microservice")
killAll.Q() close(killAll)
}, },
) )
@@ -80,7 +83,7 @@ func main() {
stop := svc.Start() stop := svc.Start()
select { select {
case <-killAll.Wait(): case <-killAll:
// This triggers termination of the service. We separate the stop // This triggers termination of the service. We separate the stop
// controls of this application versus the services embedded inside the // controls of this application versus the services embedded inside the

3
go.mod
View File

@@ -6,6 +6,7 @@ require (
github.com/cybriq/interrupt v0.0.13 github.com/cybriq/interrupt v0.0.13
github.com/cybriq/qu v0.0.19 github.com/cybriq/qu v0.0.19
go.uber.org/atomic v1.9.0 go.uber.org/atomic v1.9.0
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
google.golang.org/grpc v1.45.0 google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.0 google.golang.org/protobuf v1.28.0
@@ -21,7 +22,7 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 // indirect golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/text v0.3.3 // indirect golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
) )

5
go.sum
View File

@@ -105,6 +105,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -133,8 +135,9 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

View File

@@ -54,6 +54,9 @@ out:
log.Println(err) log.Println(err)
return err return err
} }
log.Println("received message", in)
b.transcriber.encode <- in b.transcriber.encode <- in
} }
return nil return nil