Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
dc712f9e
Commit
dc712f9e
authored
Oct 21, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Fixed tests
parent
02e52842
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
52 deletions
+40
-52
cli/parse_test.go
cli/parse_test.go
+3
-1
command_test.go
command_test.go
+37
-51
No files found.
cli/parse_test.go
View file @
dc712f9e
...
...
@@ -12,8 +12,10 @@ func TestOptionParsing(t *testing.T) {
Options
:
[]
commands
.
Option
{
commands
.
Option
{
Names
:
[]
string
{
"b"
},
Type
:
commands
.
String
},
},
Subcommands
:
map
[
string
]
*
commands
.
Command
{
"test"
:
&
commands
.
Command
{},
},
}
cmd
.
Register
(
"test"
,
&
commands
.
Command
{})
opts
,
input
,
err
:=
parseOptions
([]
string
{
"--beep"
,
"-boop=lol"
,
"test2"
,
"-c"
,
"beep"
,
"--foo=5"
})
/*for k, v := range opts {
...
...
command_test.go
View file @
dc712f9e
...
...
@@ -80,75 +80,61 @@ func TestOptionValidation(t *testing.T) {
func
TestRegistration
(
t
*
testing
.
T
)
{
noop
:=
func
(
req
Request
,
res
Response
)
{}
cmds
:=
[]
*
Command
{
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"beep"
},
Int
},
},
Run
:
noop
,
},
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"boop"
},
Int
},
},
Run
:
noop
,
},
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"boop"
},
String
},
},
Run
:
noop
,
cmdA
:=
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"beep"
},
Int
},
},
Run
:
noop
,
}
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"bop"
},
String
},
},
Run
:
noop
,
cmdB
:=
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"beep"
},
Int
},
},
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
EncShort
},
String
},
},
Run
:
noop
,
Run
:
noop
,
Subcommands
:
map
[
string
]
*
Command
{
"a"
:
cmdA
,
},
}
err
:=
cmds
[
0
]
.
Register
(
"foo"
,
cmds
[
1
])
if
err
!=
nil
{
t
.
Error
(
"Should have passed"
)
cmdC
:=
&
Command
{
Options
:
[]
Option
{
Option
{[]
string
{
"encoding"
},
String
},
},
Run
:
noop
,
}
err
=
cmds
[
0
]
.
Register
(
"bar"
,
cmds
[
2
]
)
if
err
==
nil
{
res
:=
cmdB
.
Call
(
NewRequest
([]
string
{
"a"
},
nil
,
nil
,
nil
)
)
if
res
.
Error
()
==
nil
{
t
.
Error
(
"Should have failed (option name collision)"
)
}
err
=
cmds
[
0
]
.
Register
(
"foo"
,
cmds
[
3
])
if
err
==
nil
{
t
.
Error
(
"Should have failed (subcommand name collision)"
)
}
err
=
cmds
[
0
]
.
Register
(
"baz"
,
cmds
[
4
])
if
err
==
nil
{
res
=
cmdC
.
Call
(
NewEmptyRequest
())
if
res
.
Error
()
==
nil
{
t
.
Error
(
"Should have failed (option name collision with global options)"
)
}
}
func
TestResolving
(
t
*
testing
.
T
)
{
cmd
:=
&
Command
{}
cmdA
:=
&
Command
{}
cmdB
:=
&
Command
{}
cmdB2
:=
&
Command
{}
cmdC
:=
&
Command
{}
cmd
.
Register
(
"a"
,
cmdA
)
cmdA
.
Register
(
"B"
,
cmdB2
)
cmdA
.
Register
(
"b"
,
cmdB
)
cmdB
.
Register
(
"c"
,
cmdC
)
cmdB
:=
&
Command
{
Subcommands
:
map
[
string
]
*
Command
{
"c"
:
cmdC
,
},
}
cmdB2
:=
&
Command
{}
cmdA
:=
&
Command
{
Subcommands
:
map
[
string
]
*
Command
{
"b"
:
cmdB
,
"B"
:
cmdB2
,
},
}
cmd
:=
&
Command
{
Subcommands
:
map
[
string
]
*
Command
{
"a"
:
cmdA
,
},
}
cmds
,
err
:=
cmd
.
Resolve
([]
string
{
"a"
,
"b"
,
"c"
})
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment