Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3866814e
Unverified
Commit
3866814e
authored
Sep 30, 2019
by
Andrej Ocenas
Committed by
GitHub
Sep 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Fix version selection for plugin install (#19498)
parent
93919427
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
14 deletions
+109
-14
pkg/cmd/grafana-cli/commands/install_command.go
+15
-13
pkg/cmd/grafana-cli/commands/install_command_test.go
+94
-1
No files found.
pkg/cmd/grafana-cli/commands/install_command.go
View file @
3866814e
...
...
@@ -157,32 +157,34 @@ func latestSupportedVersion(plugin *m.Plugin) *m.Version {
// SelectVersion returns latest version if none is specified or the specified version. If the version string is not
// matched to existing version it errors out. It also errors out if version that is matched is not available for current
// os and platform.
// os and platform.
It expects plugin.Versions to be sorted so the newest version is first.
func
SelectVersion
(
plugin
*
m
.
Plugin
,
version
string
)
(
*
m
.
Version
,
error
)
{
var
ver
*
m
.
Version
if
version
==
""
{
ver
=
&
plugin
.
Versions
[
0
]
var
ver
m
.
Version
latestForArch
:=
latestSupportedVersion
(
plugin
)
if
latestForArch
==
nil
{
return
nil
,
xerrors
.
New
(
"Plugin is not supported on your architecture and os."
)
}
if
version
==
""
{
return
latestForArch
,
nil
}
for
_
,
v
:=
range
plugin
.
Versions
{
if
v
.
Version
==
version
{
ver
=
&
v
ver
=
v
break
}
}
if
ver
==
nil
{
if
len
(
ver
.
Version
)
==
0
{
return
nil
,
xerrors
.
New
(
"Could not find the version you're looking for"
)
}
latestForArch
:=
latestSupportedVersion
(
plugin
)
if
latestForArch
==
nil
{
return
nil
,
xerrors
.
New
(
"Plugin is not supported on your architecture and os."
)
if
!
supportsCurrentArch
(
&
ver
)
{
return
nil
,
xerrors
.
Errorf
(
"Version you want is not supported on your architecture and os. Latest suitable version is %v"
,
latestForArch
.
Version
)
}
if
latestForArch
.
Version
==
ver
.
Version
{
return
ver
,
nil
}
return
nil
,
xerrors
.
Errorf
(
"Version you want is not supported on your architecture and os. Latest suitable version is %v"
,
latestForArch
.
Version
)
return
&
ver
,
nil
}
func
RemoveGitBuildFromName
(
pluginName
,
filename
string
)
string
{
...
...
pkg/cmd/grafana-cli/commands/install_command_test.go
View file @
3866814e
...
...
@@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
)
func
TestFolder
n
ameReplacement
(
t
*
testing
.
T
)
{
func
TestFolder
N
ameReplacement
(
t
*
testing
.
T
)
{
Convey
(
"path containing git commit path"
,
t
,
func
()
{
pluginName
:=
"datasource-plugin-kairosdb"
...
...
@@ -134,7 +134,68 @@ func TestIsPathSafe(t *testing.T) {
assert
.
False
(
t
,
isPathSafe
(
"../../"
,
dest
))
assert
.
False
(
t
,
isPathSafe
(
"../../test"
,
dest
))
})
}
func
TestSelectVersion
(
t
*
testing
.
T
)
{
t
.
Run
(
"Should return error when requested version does not exist"
,
func
(
t
*
testing
.
T
)
{
_
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"version"
}),
"1.1.1"
,
)
assert
.
NotNil
(
t
,
err
)
})
t
.
Run
(
"Should return error when no version supports current arch"
,
func
(
t
*
testing
.
T
)
{
_
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"version"
,
Arch
:
[]
string
{
"non-existent"
}}),
""
,
)
assert
.
NotNil
(
t
,
err
)
})
t
.
Run
(
"Should return error when requested version does not support current arch"
,
func
(
t
*
testing
.
T
)
{
_
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"2.0.0"
},
versionArg
{
Version
:
"1.1.1"
,
Arch
:
[]
string
{
"non-existent"
}},
),
"1.1.1"
,
)
assert
.
NotNil
(
t
,
err
)
})
t
.
Run
(
"Should return latest available for arch when no version specified"
,
func
(
t
*
testing
.
T
)
{
ver
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"2.0.0"
,
Arch
:
[]
string
{
"non-existent"
}},
versionArg
{
Version
:
"1.0.0"
},
),
""
,
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
"1.0.0"
,
ver
.
Version
)
})
t
.
Run
(
"Should return latest version when no version specified"
,
func
(
t
*
testing
.
T
)
{
ver
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"2.0.0"
},
versionArg
{
Version
:
"1.0.0"
}),
""
,
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
"2.0.0"
,
ver
.
Version
)
})
t
.
Run
(
"Should return requested version"
,
func
(
t
*
testing
.
T
)
{
ver
,
err
:=
SelectVersion
(
makePluginWithVersions
(
versionArg
{
Version
:
"2.0.0"
},
versionArg
{
Version
:
"1.0.0"
},
),
"1.0.0"
,
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
"1.0.0"
,
ver
.
Version
)
})
}
func
setupPluginInstallCmd
(
t
*
testing
.
T
,
pluginDir
string
)
utils
.
CommandLine
{
...
...
@@ -199,3 +260,35 @@ func skipWindows(t *testing.T) {
t
.
Skip
(
"Skipping test on Windows"
)
}
}
type
versionArg
struct
{
Version
string
Arch
[]
string
}
func
makePluginWithVersions
(
versions
...
versionArg
)
*
models
.
Plugin
{
plugin
:=
&
models
.
Plugin
{
Id
:
""
,
Category
:
""
,
Versions
:
[]
models
.
Version
{},
}
for
_
,
version
:=
range
versions
{
ver
:=
models
.
Version
{
Version
:
version
.
Version
,
Commit
:
fmt
.
Sprintf
(
"commit_%s"
,
version
.
Version
),
Url
:
fmt
.
Sprintf
(
"url_%s"
,
version
.
Version
),
}
if
version
.
Arch
!=
nil
{
ver
.
Arch
=
map
[
string
]
models
.
ArchMeta
{}
for
_
,
arch
:=
range
version
.
Arch
{
ver
.
Arch
[
arch
]
=
models
.
ArchMeta
{
Md5
:
fmt
.
Sprintf
(
"md5_%s"
,
arch
),
}
}
}
plugin
.
Versions
=
append
(
plugin
.
Versions
,
ver
)
}
return
plugin
}
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