summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/main.go
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2022-11-22 12:49:22 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-11-25 00:37:20 +0000
commit1a9dc75fe8099fdde9b1dd248a8fca35b001f9fc (patch)
tree729ad4b6b531ca3905434e1cbb4a950fff18dad6 /extras/hs-test/main.go
parentb79d09bbfa93f0f752f7249ad27a08eae0863a6b (diff)
hs-test: auto register test actions
Type: improvement Signed-off-by: Filip Tehlar <ftehlar@cisco.com> Change-Id: Icb5db6f69eda93181aba69b1f8676a73c0a4561b
Diffstat (limited to 'extras/hs-test/main.go')
-rwxr-xr-xextras/hs-test/main.go28
1 files changed, 12 insertions, 16 deletions
diff --git a/extras/hs-test/main.go b/extras/hs-test/main.go
index f54b6c4d910..9de0d314cb2 100755
--- a/extras/hs-test/main.go
+++ b/extras/hs-test/main.go
@@ -7,15 +7,10 @@ import (
"os"
"os/exec"
"os/signal"
-
- "git.fd.io/govpp.git/api"
+ "reflect"
)
-type CfgTable map[string]func([]string) *ActionResult
-
-var cfgTable CfgTable
-
-type ConfFn func(context.Context, api.Connection) error
+var actions Actions
func newVppContext() (context.Context, context.CancelFunc) {
ctx, cancel := signal.NotifyContext(
@@ -116,15 +111,18 @@ func OkResult() *ActionResult {
return NewActionResult(nil)
}
-func reg(key string, fn func([]string) *ActionResult) {
- cfgTable[key] = fn
-}
-
func processArgs() *ActionResult {
- fn := cfgTable[os.Args[1]]
- if fn == nil {
- return NewActionResult(fmt.Errorf("internal: no config found for %s", os.Args[1]))
+ nArgs := len(os.Args) - 1 // skip program name
+ if nArgs < 1 {
+ return NewActionResult(fmt.Errorf("internal: no action specified!"))
+ }
+ action := os.Args[1]
+ methodValue := reflect.ValueOf(&actions).MethodByName(action)
+ if !methodValue.IsValid() {
+ return NewActionResult(fmt.Errorf("internal unknown action %s!", action))
}
+ methodIface := methodValue.Interface()
+ fn := methodIface.(func([]string) *ActionResult)
return fn(os.Args)
}
@@ -144,8 +142,6 @@ func main() {
os.Exit(0)
}
- RegisterActions()
-
var err error
res := processArgs()
err = writeSyncFile(res)