zrok test loop -> zrok test loop public (#237)

This commit is contained in:
Michael Quigley 2023-02-16 14:50:07 -05:00
parent 21a019ae4f
commit bca3133de5
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 18 additions and 11 deletions

View File

@ -19,6 +19,7 @@ func init() {
adminCmd.AddCommand(adminDeleteCmd) adminCmd.AddCommand(adminDeleteCmd)
adminCmd.AddCommand(adminListCmd) adminCmd.AddCommand(adminListCmd)
adminCmd.AddCommand(adminUpdateCmd) adminCmd.AddCommand(adminUpdateCmd)
testCmd.AddCommand(loopCmd)
rootCmd.AddCommand(adminCmd) rootCmd.AddCommand(adminCmd)
rootCmd.AddCommand(configCmd) rootCmd.AddCommand(configCmd)
rootCmd.AddCommand(shareCmd) rootCmd.AddCommand(shareCmd)
@ -72,6 +73,12 @@ var configCmd = &cobra.Command{
Short: "Configure your zrok environment", Short: "Configure your zrok environment",
} }
var loopCmd = &cobra.Command{
Use: "loopback",
Aliases: []string{"loop"},
Short: "Loopback testing utilities",
}
var shareCmd = &cobra.Command{ var shareCmd = &cobra.Command{
Use: "share", Use: "share",
Short: "Create backend access for shares", Short: "Create backend access for shares",

View File

@ -28,10 +28,10 @@ import (
) )
func init() { func init() {
testCmd.AddCommand(newLoopCmd().cmd) loopCmd.AddCommand(newTestLoopPublicCommand().cmd)
} }
type loopCmd struct { type testLoopPublicCommand struct {
cmd *cobra.Command cmd *cobra.Command
loopers int loopers int
iterations int iterations int
@ -46,13 +46,13 @@ type loopCmd struct {
frontendSelection []string frontendSelection []string
} }
func newLoopCmd() *loopCmd { func newTestLoopPublicCommand() *testLoopPublicCommand {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "loop", Use: "public",
Short: "Start a loop agent", Short: "Start a loop agent testing public proxy shares",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
} }
r := &loopCmd{cmd: cmd} r := &testLoopPublicCommand{cmd: cmd}
cmd.Run = r.run cmd.Run = r.run
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start") cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper") cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper")
@ -68,10 +68,10 @@ func newLoopCmd() *loopCmd {
return r return r
} }
func (r *loopCmd) run(_ *cobra.Command, _ []string) { func (cmd *testLoopPublicCommand) run(_ *cobra.Command, _ []string) {
var loopers []*looper var loopers []*looper
for i := 0; i < r.loopers; i++ { for i := 0; i < cmd.loopers; i++ {
l := newLooper(i, r) l := newLooper(i, cmd)
loopers = append(loopers, l) loopers = append(loopers, l)
go l.run() go l.run()
} }
@ -105,7 +105,7 @@ func (r *loopCmd) run(_ *cobra.Command, _ []string) {
type looper struct { type looper struct {
id int id int
cmd *loopCmd cmd *testLoopPublicCommand
env *zrokdir.Environment env *zrokdir.Environment
done chan struct{} done chan struct{}
listener edge.Listener listener edge.Listener
@ -122,7 +122,7 @@ type looper struct {
stop bool stop bool
} }
func newLooper(id int, cmd *loopCmd) *looper { func newLooper(id int, cmd *testLoopPublicCommand) *looper {
return &looper{ return &looper{
id: id, id: id,
cmd: cmd, cmd: cmd,