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
ea9ac0d2
Commit
ea9ac0d2
authored
Feb 15, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(cli): improve unittests
parent
74625771
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
46 deletions
+82
-46
pkg/cmd/grafana-cli/commands/commandstest/fake_ioutil.go
+2
-2
pkg/cmd/grafana-cli/commands/ls_command.go
+5
-12
pkg/cmd/grafana-cli/commands/ls_command_test.go
+73
-30
pkg/cmd/grafana-cli/services/io_util.go
+2
-2
No files found.
pkg/cmd/grafana-cli/commands/commandstest/fake_ioutil.go
View file @
ea9ac0d2
...
...
@@ -11,7 +11,7 @@ type FakeIoUtil struct {
}
func
(
util
*
FakeIoUtil
)
Stat
(
path
string
)
(
os
.
FileInfo
,
error
)
{
return
FakeFileInfo
{
IsDirectory
:
util
.
FakeIsDirectory
},
nil
return
&
FakeFileInfo
{
IsDirectory
:
util
.
FakeIsDirectory
},
nil
}
func
(
util
*
FakeIoUtil
)
RemoveAll
(
path
string
)
error
{
...
...
@@ -30,7 +30,7 @@ type FakeFileInfo struct {
IsDirectory
bool
}
func
(
ffi
FakeFileInfo
)
IsDir
()
bool
{
func
(
ffi
*
FakeFileInfo
)
IsDir
()
bool
{
return
ffi
.
IsDirectory
}
...
...
pkg/cmd/grafana-cli/commands/ls_command.go
View file @
ea9ac0d2
...
...
@@ -7,22 +7,15 @@ import (
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
)
var
getPlugins
func
(
path
string
)
[]
m
.
InstalledPlugin
var
ls_getPlugins
func
(
path
string
)
[]
m
.
InstalledPlugin
=
s
.
GetLocalPlugins
var
GetStat
m
.
IoUtil
func
init
()
{
getPlugins
=
s
.
GetLocalPlugins
GetStat
=
s
.
IoUtil
}
func
validateCommand
(
pluginDir
string
)
error
{
var
validateLsCommmand
=
func
(
pluginDir
string
)
error
{
if
pluginDir
==
""
{
return
errors
.
New
(
"missing path flag"
)
}
log
.
Info
(
"plugindir: "
+
pluginDir
+
"
\n
"
)
pluginDirInfo
,
err
:=
GetStat
.
Stat
(
pluginDir
)
pluginDirInfo
,
err
:=
s
.
IoHelper
.
Stat
(
pluginDir
)
if
err
!=
nil
{
return
errors
.
New
(
"missing path flag"
)
...
...
@@ -37,11 +30,11 @@ func validateCommand(pluginDir string) error {
func
lsCommand
(
c
CommandLine
)
error
{
pluginDir
:=
c
.
GlobalString
(
"path"
)
if
err
:=
validate
Co
mmand
(
pluginDir
);
err
!=
nil
{
if
err
:=
validate
LsCom
mmand
(
pluginDir
);
err
!=
nil
{
return
err
}
for
_
,
plugin
:=
range
getPlugins
(
pluginDir
)
{
for
_
,
plugin
:=
range
ls_
getPlugins
(
pluginDir
)
{
log
.
Infof
(
"plugin: %s @ %s
\n
"
,
plugin
.
Name
,
plugin
.
Info
.
Version
)
}
...
...
pkg/cmd/grafana-cli/commands/ls_command_test.go
View file @
ea9ac0d2
package
commands
import
(
"testing"
"errors"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/commandstest"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
.
"github.com/smartystreets/goconvey/convey"
"testing"
)
func
TestMissingPath
(
t
*
testing
.
T
)
{
Convey
(
"Missing path"
,
t
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
""
,
var
org
=
validateLsCommmand
Convey
(
"ls command"
,
t
,
func
()
{
validateLsCommmand
=
org
Convey
(
"Missing path"
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
""
,
},
},
},
}
s
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{}
}
s
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{}
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
,
ShouldNotBeNil
)
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
,
ShouldNotBeNil
)
})
})
})
Convey
(
"Path is not a directory"
,
t
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
"/var/lib/grafana/plugins"
,
Convey
(
"Path is not a directory"
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
"/var/lib/grafana/plugins"
,
},
},
},
}
GetStat
=
&
commandstest
.
FakeIoUtil
{
FakeIsDirectory
:
false
,
}
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
,
ShouldNotBeNil
)
}
s
.
IoHelper
=
&
commandstest
.
FakeIoUtil
{
FakeIsDirectory
:
false
,
}
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
,
ShouldNotBeNil
)
})
})
Convey
(
"can override validateLsCommand"
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
"/var/lib/grafana/plugins"
,
},
},
}
validateLsCommmand
=
func
(
pluginDir
string
)
error
{
return
errors
.
New
(
"dummie error"
)
}
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
.
Error
(),
ShouldEqual
,
"dummie error"
)
})
})
Convey
(
"Validate that validateLsCommand is reset"
,
func
()
{
commandLine
:=
&
commandstest
.
FakeCommandLine
{
CliArgs
:
[]
string
{
"ls"
},
GlobalFlags
:
&
commandstest
.
FakeFlagger
{
Data
:
map
[
string
]
interface
{}{
"path"
:
"/var/lib/grafana/plugins"
,
},
},
}
Convey
(
"should return error"
,
func
()
{
err
:=
lsCommand
(
commandLine
)
So
(
err
.
Error
(),
ShouldNotEqual
,
"dummie error"
)
})
})
})
}
pkg/cmd/grafana-cli/services/io_util.go
View file @
ea9ac0d2
package
services
import
(
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
//
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"io/ioutil"
"os"
)
var
IoUtil
m
.
IoUtil
=
IoUtilImp
{}
//var IoUtils
m.IoUtil = IoUtilImp{}
type
IoUtilImp
struct
{
}
...
...
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