Skip to content

Commit eb65649

Browse files
committed
Fixing test: solving regression in lib search output
1 parent bdf3772 commit eb65649

File tree

4 files changed

+133
-135
lines changed

4 files changed

+133
-135
lines changed

cli/lib/search.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6565
os.Exit(cli.ErrGeneric)
6666
}
6767

68-
results := searchResp.GetSearchOutput()
69-
if cli.OutputJSONOrElse(results) {
68+
if cli.OutputJSONOrElse(searchResp) {
69+
results := searchResp.GetLibraries()
7070
if len(results) > 0 {
7171
for _, out := range results {
72-
fmt.Println(SearchOutputToString(out, searchFlags.names))
72+
fmt.Println(searchedLibraryToString(out, searchFlags.names))
7373
}
7474
} else {
7575
formatter.Print("No libraries matching your search.")
@@ -78,7 +78,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
7878
logrus.Info("Done")
7979
}
8080

81-
func SearchOutputToString(lsr *rpc.SearchLibraryOutput, names bool) string {
81+
func searchedLibraryToString(lsr *rpc.SearchedLibrary, names bool) string {
8282
ret := ""
8383

8484
ret += fmt.Sprintf("Name: \"%s\"\n", lsr.Name)
@@ -91,16 +91,15 @@ func SearchOutputToString(lsr *rpc.SearchLibraryOutput, names bool) string {
9191
fmt.Sprintln(" Category: ", lsr.GetLatest().Category) +
9292
fmt.Sprintln(" Architecture: ", strings.Join(lsr.GetLatest().Architectures, ", ")) +
9393
fmt.Sprintln(" Types: ", strings.Join(lsr.GetLatest().Types, ", ")) +
94-
fmt.Sprintln(" Versions: ", strings.Replace(fmt.Sprint(Versions(lsr.GetLatest(), lsr)), " ", ", ", -1))
94+
fmt.Sprintln(" Versions: ", strings.Replace(fmt.Sprint(versionsFromSearchedLibrary(lsr)), " ", ", ", -1))
9595
}
9696
return strings.TrimSpace(ret)
9797
}
9898

99-
func Versions(l *rpc.LibraryRelease, library *rpc.SearchLibraryOutput) []*semver.Version {
99+
func versionsFromSearchedLibrary(library *rpc.SearchedLibrary) []*semver.Version {
100100
res := []*semver.Version{}
101-
for str, _ := range library.Releases {
102-
v, err := semver.Parse(str)
103-
if err == nil {
101+
for str := range library.Releases {
102+
if v, err := semver.Parse(str); err == nil {
104103
res = append(res, v)
105104
}
106105
}

commands/lib/search.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
3434
return nil, errors.New("invalid instance")
3535
}
3636

37-
res := []*rpc.SearchLibraryOutput{}
37+
res := []*rpc.SearchedLibrary{}
3838

3939
for _, lib := range lm.Index.Libraries {
4040
if strings.Contains(strings.ToLower(lib.Name), strings.ToLower(req.GetQuery())) {
@@ -44,7 +44,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
4444
}
4545
latest := GetLibraryParameters(lib.Latest)
4646

47-
searchedlib := &rpc.SearchLibraryOutput{
47+
searchedlib := &rpc.SearchedLibrary{
4848
Name: lib.Name,
4949
Releases: releases,
5050
Latest: latest,
@@ -54,9 +54,9 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
5454
}
5555

5656
if req.GetNames() {
57-
restmp := []*rpc.SearchLibraryOutput{}
57+
restmp := []*rpc.SearchedLibrary{}
5858
for _, lib := range res {
59-
searchedlib := &rpc.SearchLibraryOutput{
59+
searchedlib := &rpc.SearchedLibrary{
6060
Name: lib.Name,
6161
}
6262
restmp = append(restmp, searchedlib)
@@ -68,7 +68,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
6868
}
6969
}
7070

71-
return &rpc.LibrarySearchResp{SearchOutput: res}, nil
71+
return &rpc.LibrarySearchResp{Libraries: res}, nil
7272
}
7373

7474
func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease {

0 commit comments

Comments
 (0)