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
2b938721
Unverified
Commit
2b938721
authored
Jan 07, 2021
by
Emil Hessman
Committed by
GitHub
Jan 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite tsdb influxdb test to standard library (#30091)
parent
fd1b2904
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
53 deletions
+40
-53
pkg/tsdb/influxdb/influxdb_test.go
+40
-53
No files found.
pkg/tsdb/influxdb/influxdb_test.go
View file @
2b938721
...
...
@@ -8,69 +8,56 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestInfluxDB
(
t
*
testing
.
T
)
{
Convey
(
"InfluxDB"
,
t
,
func
()
{
datasource
:=
&
models
.
DataSource
{
Url
:
"http://awesome-influxdb:1337"
,
Database
:
"awesome-db"
,
JsonData
:
simplejson
.
New
(),
}
query
:=
"SELECT awesomeness FROM somewhere"
e
:=
&
InfluxDBExecutor
{
QueryParser
:
&
InfluxdbQueryParser
{},
ResponseParser
:
&
ResponseParser
{},
}
Convey
(
"createRequest with GET httpMode"
,
func
()
{
req
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
So
(
err
,
ShouldBeNil
)
func
TestInfluxDBExecutor_createRequest
(
t
*
testing
.
T
)
{
datasource
:=
&
models
.
DataSource
{
Url
:
"http://awesome-influxdb:1337"
,
Database
:
"awesome-db"
,
JsonData
:
simplejson
.
New
(),
}
query
:=
"SELECT awesomeness FROM somewhere"
e
:=
&
InfluxDBExecutor
{
QueryParser
:
&
InfluxdbQueryParser
{},
ResponseParser
:
&
ResponseParser
{},
}
Convey
(
"as default"
,
func
(
)
{
So
(
req
.
Method
,
ShouldEqual
,
"GET"
)
}
)
t
.
Run
(
"createRequest with GET httpMode"
,
func
(
t
*
testing
.
T
)
{
req
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
require
.
NoError
(
t
,
err
)
Convey
(
"has a 'q' GET param that equals to query"
,
func
()
{
q
:=
req
.
URL
.
Query
()
.
Get
(
"q"
)
So
(
q
,
ShouldEqual
,
query
)
})
assert
.
Equal
(
t
,
"GET"
,
req
.
Method
)
Convey
(
"has an empty body"
,
func
()
{
So
(
req
.
Body
,
ShouldEqual
,
nil
)
})
})
q
:=
req
.
URL
.
Query
()
.
Get
(
"q"
)
assert
.
Equal
(
t
,
query
,
q
)
Convey
(
"createRequest with POST httpMode"
,
func
()
{
datasource
.
JsonData
.
Set
(
"httpMode"
,
"POST"
)
req
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
So
(
err
,
ShouldBeNil
)
assert
.
Nil
(
t
,
req
.
Body
)
})
t
.
Run
(
"createRequest with POST httpMode"
,
func
(
t
*
testing
.
T
)
{
datasource
.
JsonData
.
Set
(
"httpMode"
,
"POST"
)
req
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
require
.
NoError
(
t
,
err
)
Convey
(
"method should be POST"
,
func
()
{
So
(
req
.
Method
,
ShouldEqual
,
"POST"
)
})
assert
.
Equal
(
t
,
"POST"
,
req
.
Method
)
Convey
(
"has no 'q' GET param"
,
func
()
{
q
:=
req
.
URL
.
Query
()
.
Get
(
"q"
)
So
(
q
,
ShouldEqual
,
""
)
})
q
:=
req
.
URL
.
Query
()
.
Get
(
"q"
)
assert
.
Empty
(
t
,
q
)
Convey
(
"has the request as GET param in body"
,
func
()
{
body
,
_
:=
ioutil
.
ReadAll
(
req
.
Body
)
testBodyValues
:=
url
.
Values
{}
testBodyValues
.
Add
(
"q"
,
query
)
testBody
:=
testBodyValues
.
Encode
()
So
(
string
(
body
),
ShouldEqual
,
testBody
)
})
})
body
,
err
:=
ioutil
.
ReadAll
(
req
.
Body
)
require
.
NoError
(
t
,
err
)
Convey
(
"createRequest with PUT httpMode"
,
func
()
{
datasource
.
JsonData
.
Set
(
"httpMode"
,
"PUT"
)
_
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
testBodyValues
:=
url
.
Values
{}
testBodyValues
.
Add
(
"q"
,
query
)
testBody
:=
testBodyValues
.
Encode
()
assert
.
Equal
(
t
,
testBody
,
string
(
body
))
})
Convey
(
"should miserably fail"
,
func
(
)
{
So
(
err
,
ShouldEqual
,
ErrInvalidHttpMode
)
}
)
}
)
t
.
Run
(
"createRequest with PUT httpMode"
,
func
(
t
*
testing
.
T
)
{
datasource
.
JsonData
.
Set
(
"httpMode"
,
"PUT"
)
_
,
err
:=
e
.
createRequest
(
context
.
Background
(),
datasource
,
query
)
require
.
EqualError
(
t
,
err
,
ErrInvalidHttpMode
.
Error
()
)
})
}
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