@@ -19,9 +19,14 @@ var mockServers = &upcloud.Servers{Servers: []upcloud.Server{
1919 {Title : "bock1" , UUID : "jklmno" , Hostname : "faa" },
2020 {Title : "bock2" , UUID : "pqrstu" , Hostname : "fii" },
2121 {Title : "dock1" , UUID : "vwxyzä" , Hostname : "bfoo" },
22+ {Title : "case started" , UUID : "started" , Hostname : "astarted" , State : "started" },
23+ {Title : "case stopped" , UUID : "stopped" , Hostname : "astopped" , State : "stopped" },
2224}}
2325
2426func TestServer_CompleteArgument (t * testing.T ) {
27+ mService := new (smock.Service )
28+ mService .On ("GetServers" , mock .Anything ).Return (mockServers , nil )
29+
2530 for _ , test := range []struct {
2631 name string
2732 complete string
@@ -37,13 +42,23 @@ func TestServer_CompleteArgument(t *testing.T) {
3742 {name : "hostnames and titles" , complete : "b" , expectedMatches : []string {"bock1" , "bock2" , "bfoo" }, expectedDirective : cobra .ShellCompDirectiveNoFileComp },
3843 } {
3944 t .Run (test .name , func (t * testing.T ) {
40- mService := new (smock.Service )
41- mService .On ("GetServers" , mock .Anything ).Return (mockServers , nil )
42- ips , directive := completion.Server {}.CompleteArgument (context .TODO (), mService , test .complete )
43- assert .Equal (t , test .expectedMatches , ips )
45+ servers , directive := completion.Server {}.CompleteArgument (context .TODO (), mService , test .complete )
46+ assert .Equal (t , test .expectedMatches , servers )
4447 assert .Equal (t , test .expectedDirective , directive )
4548 })
4649 }
50+
51+ t .Run ("stopped" , func (t * testing.T ) {
52+ servers , directive := completion.StoppedServer {}.CompleteArgument (context .TODO (), mService , "s" )
53+ assert .Equal (t , []string {"stopped" }, servers )
54+ assert .Equal (t , cobra .ShellCompDirectiveNoFileComp , directive )
55+ })
56+
57+ t .Run ("started" , func (t * testing.T ) {
58+ servers , directive := completion.StartedServer {}.CompleteArgument (context .TODO (), mService , "s" )
59+ assert .Equal (t , []string {"started" }, servers )
60+ assert .Equal (t , cobra .ShellCompDirectiveNoFileComp , directive )
61+ })
4762}
4863
4964func TestServer_CompleteArgumentServiceFail (t * testing.T ) {
0 commit comments