Skip to content

Commit

Permalink
test(munit): add tests for munit
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeguo committed Jul 29, 2024
1 parent 9c9e4a9 commit 67bdbea
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 336 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"MINIT"
]
}
308 changes: 0 additions & 308 deletions pkg/munit/load.go

This file was deleted.

50 changes: 50 additions & 0 deletions pkg/munit/load_args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package munit

import (
"path/filepath"
"strings"
)

// LoadArgs loads unit from command line arguments
func LoadArgs(args []string) (unit Unit, ok bool, err error) {
var opts []string

// fix a history issue
for len(args) > 0 {
if filepath.Base(args[0]) == "minit" {
args = args[1:]
} else {
break
}
}

// extract arguments after '--' if existed
for i, item := range args {
if item == "--" {
opts = args[0:i]
args = args[i+1:]
break
}
}

if len(args) == 0 {
return
}

unit = Unit{
Name: "arg-main",
Kind: KindDaemon,
Command: args,
}

// opts decoding
for _, opt := range opts {
if strings.HasSuffix(opt, "-"+KindOnce) {
unit.Kind = KindOnce
}
}

ok = true

return
}
Loading

0 comments on commit 67bdbea

Please sign in to comment.