-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from mesg-foundation/feature/service-list
extend ListServices api to filter by running services, closes #496
- Loading branch information
Showing
14 changed files
with
326 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package commands | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mesg-foundation/core/protobuf/coreapi" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestServiceList(t *testing.T) { | ||
var ( | ||
services = []*coreapi.Service{ | ||
{ID: "1", Name: "a", Status: coreapi.Service_RUNNING}, | ||
{ID: "2", Name: "b", Status: coreapi.Service_PARTIAL}, | ||
} | ||
m = newMockExecutor() | ||
c = newServiceListCmd(m) | ||
) | ||
|
||
m.On("ServiceList").Return(services, nil) | ||
|
||
closeStd := captureStd(t) | ||
c.cmd.Execute() | ||
stdout, _ := closeStd() | ||
r := bufio.NewReader(strings.NewReader(stdout)) | ||
|
||
for _, s := range []string{ | ||
`Listing services\.\.\.`, | ||
`STATUS\s+SERVICE\s+NAME`, | ||
} { | ||
matched, err := regexp.Match(fmt.Sprintf(`^\s*%s\s*$`, s), readLine(t, r)) | ||
require.NoError(t, err) | ||
require.True(t, matched) | ||
} | ||
|
||
for _, s := range services { | ||
status := strings.ToLower(s.Status.String()) | ||
pattern := fmt.Sprintf(`^\s*%s\s+%s\s+%s\s*$`, status, s.ID, s.Name) | ||
matched, err := regexp.Match(pattern, readLine(t, r)) | ||
require.NoError(t, err) | ||
require.True(t, matched) | ||
} | ||
} | ||
|
||
func readLine(t *testing.T, r *bufio.Reader) []byte { | ||
line, _, err := r.ReadLine() | ||
require.NoError(t, err) | ||
return line | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.