[hot-fix] fix tests

mine
derailed 2025-07-19 09:27:46 -06:00
parent fcf79b2f5a
commit ffdc7b70f0
2 changed files with 36 additions and 13 deletions

View File

@ -29,17 +29,18 @@ func NewInterpreter(s string) *Interpreter {
// ClearNS clears the current namespace if any. // ClearNS clears the current namespace if any.
func (c *Interpreter) ClearNS() { func (c *Interpreter) ClearNS() {
if !c.HasNS() { c.SwitchNS(client.BlankNamespace)
return
}
if ons, ok := c.NSArg(); ok {
c.Reset(strings.TrimSpace(strings.Replace(c.line, " "+ons, "", 1)))
}
} }
// SwitchNS replaces the current namespace with the provided one. // SwitchNS replaces the current namespace with the provided one.
func (c *Interpreter) SwitchNS(ns string) { func (c *Interpreter) SwitchNS(ns string) {
c.args[nsKey] = ns if ons, ok := c.NSArg(); ok && ons != client.BlankNamespace {
c.Reset(strings.TrimSpace(strings.Replace(c.line, " "+ons, " "+ns, 1)))
return
}
if ns != client.BlankNamespace {
c.Reset(strings.TrimSpace(c.line) + " " + ns)
}
} }
func (c *Interpreter) grok() { func (c *Interpreter) grok() {

View File

@ -85,10 +85,15 @@ func TestSwitchNS(t *testing.T) {
}{ }{
"empty": {}, "empty": {},
"blank": {
cmd: "pod fred",
e: "pod",
},
"no-op": { "no-op": {
cmd: "pod fred", cmd: "pod fred",
ns: "blee", ns: "fred",
e: "pod blee", e: "pod fred",
}, },
"no-ns": { "no-ns": {
@ -97,8 +102,20 @@ func TestSwitchNS(t *testing.T) {
e: "pod blee", e: "pod blee",
}, },
"happy": { "full-ns": {
cmd: "pod app=blee @zorg fred", cmd: "pod app=blee fred @zorg",
ns: "blee",
e: "pod app=blee blee @zorg",
},
"full--repeat-ns": {
cmd: "pod app=zorg zorg @zorg",
ns: "blee",
e: "pod app=zorg blee @zorg",
},
"full-no-ns": {
cmd: "pod app=blee @zorg",
ns: "blee", ns: "blee",
e: "pod app=blee @zorg blee", e: "pod app=blee @zorg blee",
}, },
@ -121,7 +138,7 @@ func TestClearNS(t *testing.T) {
}{ }{
"empty": {}, "empty": {},
"no-op": { "has-ns": {
cmd: "pod fred", cmd: "pod fred",
e: "pod", e: "pod",
}, },
@ -131,10 +148,15 @@ func TestClearNS(t *testing.T) {
e: "pod", e: "pod",
}, },
"happy": { "full-repeat-ns": {
cmd: "pod app=blee @zorg zorg", cmd: "pod app=blee @zorg zorg",
e: "pod app=blee @zorg", e: "pod app=blee @zorg",
}, },
"full-no-ns": {
cmd: "pod app=blee @zorg",
e: "pod app=blee @zorg",
},
} }
for k := range uu { for k := range uu {