@@ -10,37 +10,58 @@ func TestService_ExecuteCommand_ListResources(t *testing.T) {
1010 svc := NewService (ServiceDefinition {
1111 ServerURL : "http://test.com" ,
1212 Resources : map [string ]* Resource {
13+ "project" : & projectResource ,
1314 "user" : {},
1415 "post" : {},
1516 "comment" : {},
1617 },
1718 }, nil )
1819
1920 tests := []struct {
20- name string
21- args []string
22- expected string
21+ name string
22+ args []string
23+ expectAsError bool
24+ expected string
2325 }{
2426 {
2527 name : "no arguments" ,
2628 args : []string {},
27- expected : "Available resources:\n - comment\n - post\n - user\n " ,
29+ expected : "Available resources:\n - comment\n - post\n - project \n - user\n " ,
2830 },
2931 {
3032 name : "help flag" ,
3133 args : []string {"--help" },
32- expected : "Available resources:\n - comment\n - post\n - user\n " ,
34+ expected : "Available resources:\n - comment\n - post\n - project\n - user\n " ,
35+ },
36+ {
37+ name : "unknown resource" ,
38+ args : []string {"users" },
39+ expectAsError : true ,
40+ expected : "Resource \" users\" not found" ,
41+ },
42+ {
43+ name : "help for project" ,
44+ args : []string {"project" , "--help" },
45+ expected : "Available Commands:" ,
46+ },
47+ {
48+ name : "help for project" ,
49+ args : []string {"project" },
50+ expected : "Available Commands:" ,
3351 },
3452 }
3553
3654 for _ , tt := range tests {
3755 t .Run (tt .name , func (t * testing.T ) {
3856 result , err := svc .ExecuteCommand (tt .args )
3957 if err != nil {
40- t .Errorf ("ExecuteCommand() error = %v, expected no error" , err )
41- }
42- if ! strings .Contains (result , tt .expected ) {
43- t .Errorf ("ExecuteCommand() = %v, expected it to contain %v" , result , tt .expected )
58+ if ! tt .expectAsError {
59+ t .Errorf ("ExecuteCommand() error = %v, expected no error" , err )
60+ } else if ! strings .Contains (err .Error (), tt .expected ) {
61+ t .Errorf ("ExecuteCommand() error = %v, expected it to contain %v" , err , tt .expected )
62+ }
63+ } else if ! strings .Contains (result , tt .expected ) {
64+ t .Errorf ("ExecuteCommand() = %q, expected it to contain %q" , result , tt .expected )
4465 }
4566 })
4667 }
0 commit comments