Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
fa96057b
Commit
fa96057b
authored
Feb 02, 2017
by
Matt Butcher
Committed by
GitHub
Feb 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1900 from technosophos/fix/1897-search-sort-order
fix(helm): fix sort order on helm search
parents
c1e66832
f018364f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
6 deletions
+33
-6
search.go
cmd/helm/search/search.go
+4
-1
search_test.go
cmd/helm/search/search_test.go
+27
-3
search_test.go
cmd/helm/search_test.go
+2
-2
No files found.
cmd/helm/search/search.go
View file @
fa96057b
...
...
@@ -62,6 +62,7 @@ const verSep = "$$"
// AddRepo adds a repository index to the search index.
func
(
i
*
Index
)
AddRepo
(
rname
string
,
ind
*
repo
.
IndexFile
,
all
bool
)
{
ind
.
SortEntries
()
for
name
,
ref
:=
range
ind
.
Entries
{
if
len
(
ref
)
==
0
{
// Skip chart names that have zero releases.
...
...
@@ -175,7 +176,7 @@ func (i *Index) SearchRegexp(re string, threshold int) ([]*Result, error) {
return
buf
,
nil
}
// Chart returns the Chart
Ref
for a particular name.
// Chart returns the Chart
Version
for a particular name.
func
(
i
*
Index
)
Chart
(
name
string
)
(
*
repo
.
ChartVersion
,
error
)
{
c
,
ok
:=
i
.
charts
[
name
]
if
!
ok
{
...
...
@@ -220,6 +221,8 @@ func (s scoreSorter) Less(a, b int) bool {
if
err
!=
nil
{
return
true
}
// Sort so that the newest chart is higher than the oldest chart. This is
// the opposite of what you'd expect in a function called Less.
return
v1
.
GreaterThan
(
v2
)
}
return
first
.
Name
<
second
.
Name
...
...
cmd/helm/search/search_test.go
View file @
fa96057b
...
...
@@ -26,14 +26,16 @@ import (
func
TestSortScore
(
t
*
testing
.
T
)
{
in
:=
[]
*
Result
{
{
Name
:
"bbb"
,
Score
:
0
},
{
Name
:
"bbb"
,
Score
:
0
,
Chart
:
&
repo
.
ChartVersion
{
Metadata
:
&
chart
.
Metadata
{
Version
:
"1.2.3"
}}
},
{
Name
:
"aaa"
,
Score
:
5
},
{
Name
:
"abb"
,
Score
:
5
},
{
Name
:
"aab"
,
Score
:
0
},
{
Name
:
"bab"
,
Score
:
5
},
{
Name
:
"ver"
,
Score
:
5
,
Chart
:
&
repo
.
ChartVersion
{
Metadata
:
&
chart
.
Metadata
{
Version
:
"1.2.4"
}}},
{
Name
:
"ver"
,
Score
:
5
,
Chart
:
&
repo
.
ChartVersion
{
Metadata
:
&
chart
.
Metadata
{
Version
:
"1.2.3"
}}},
}
expect
:=
[]
string
{
"aab"
,
"bbb"
,
"aaa"
,
"abb"
,
"bab"
}
expectScore
:=
[]
int
{
0
,
0
,
5
,
5
,
5
}
expect
:=
[]
string
{
"aab"
,
"bbb"
,
"aaa"
,
"abb"
,
"bab"
,
"ver"
,
"ver"
}
expectScore
:=
[]
int
{
0
,
0
,
5
,
5
,
5
,
5
,
5
}
SortScore
(
in
)
// Test Score
...
...
@@ -48,6 +50,14 @@ func TestSortScore(t *testing.T) {
t
.
Errorf
(
"Sort error: expected %s, got %s"
,
expect
[
i
],
in
[
i
]
.
Name
)
}
}
// Test version of last two items
if
in
[
5
]
.
Chart
.
Version
!=
"1.2.4"
{
t
.
Errorf
(
"Expected 1.2.4, got %s"
,
in
[
5
]
.
Chart
.
Version
)
}
if
in
[
6
]
.
Chart
.
Version
!=
"1.2.3"
{
t
.
Error
(
"Expected 1.2.3 to be last"
)
}
}
var
indexfileEntries
=
map
[
string
]
repo
.
ChartVersions
{
...
...
@@ -123,6 +133,20 @@ func TestAll(t *testing.T) {
}
}
func
TestAddRepo_Sort
(
t
*
testing
.
T
)
{
i
:=
loadTestIndex
(
t
,
true
)
sr
,
err
:=
i
.
Search
(
"testing/santa-maria"
,
100
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ch
:=
sr
[
0
]
expect
:=
"1.2.3"
if
ch
.
Chart
.
Version
!=
expect
{
t
.
Errorf
(
"Expected %q, got %q"
,
expect
,
ch
.
Chart
.
Version
)
}
}
func
TestSearchByName
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
...
...
cmd/helm/search_test.go
View file @
fa96057b
...
...
@@ -39,7 +39,7 @@ func TestSearchCmd(t *testing.T) {
{
name
:
"search for 'alpine', expect two matches"
,
args
:
[]
string
{
"alpine"
},
expect
:
"NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.
1
.0
\t
Deploy a basic Alpine Linux pod"
,
expect
:
"NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.
2
.0
\t
Deploy a basic Alpine Linux pod"
,
},
{
name
:
"search for 'alpine' with versions, expect three matches"
,
...
...
@@ -56,7 +56,7 @@ func TestSearchCmd(t *testing.T) {
name
:
"search for 'alp[a-z]+', expect two matches"
,
args
:
[]
string
{
"alp[a-z]+"
},
flags
:
[]
string
{
"--regexp"
},
expect
:
"NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.
1
.0
\t
Deploy a basic Alpine Linux pod"
,
expect
:
"NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.
2
.0
\t
Deploy a basic Alpine Linux pod"
,
regexp
:
true
,
},
{
...
...
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