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
28aafcd7
Commit
28aafcd7
authored
Feb 05, 2019
by
jeroenvollenbrock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cloudwatch: Add tests for resource_arn template query
parent
fa977ce0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
pkg/tsdb/cloudwatch/metric_find_query_test.go
+57
-0
public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts
+23
-0
No files found.
pkg/tsdb/cloudwatch/metric_find_query_test.go
View file @
28aafcd7
...
...
@@ -8,6 +8,8 @@ import (
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi/resourcegroupstaggingapiiface"
"github.com/bmizerany/assert"
"github.com/grafana/grafana/pkg/components/securejsondata"
"github.com/grafana/grafana/pkg/components/simplejson"
...
...
@@ -22,6 +24,11 @@ type mockedEc2 struct {
RespRegions
ec2
.
DescribeRegionsOutput
}
type
mockedRGTA
struct
{
resourcegroupstaggingapiiface
.
ResourceGroupsTaggingAPIAPI
Resp
resourcegroupstaggingapi
.
GetResourcesOutput
}
func
(
m
mockedEc2
)
DescribeInstancesPages
(
in
*
ec2
.
DescribeInstancesInput
,
fn
func
(
*
ec2
.
DescribeInstancesOutput
,
bool
)
bool
)
error
{
fn
(
&
m
.
Resp
,
true
)
return
nil
...
...
@@ -30,6 +37,11 @@ func (m mockedEc2) DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.DescribeR
return
&
m
.
RespRegions
,
nil
}
func
(
m
mockedRGTA
)
GetResourcesPages
(
in
*
resourcegroupstaggingapi
.
GetResourcesInput
,
fn
func
(
*
resourcegroupstaggingapi
.
GetResourcesOutput
,
bool
)
bool
)
error
{
fn
(
&
m
.
Resp
,
true
)
return
nil
}
func
TestCloudWatchMetrics
(
t
*
testing
.
T
)
{
Convey
(
"When calling getMetricsForCustomMetrics"
,
t
,
func
()
{
...
...
@@ -209,6 +221,51 @@ func TestCloudWatchMetrics(t *testing.T) {
So
(
result
[
7
]
.
Text
,
ShouldEqual
,
"vol-4-2"
)
})
})
Convey
(
"When calling handleGetResourceArns"
,
t
,
func
()
{
executor
:=
&
CloudWatchExecutor
{
rgtaSvc
:
mockedRGTA
{
Resp
:
resourcegroupstaggingapi
.
GetResourcesOutput
{
ResourceTagMappingList
:
[]
*
resourcegroupstaggingapi
.
ResourceTagMapping
{
{
ResourceARN
:
aws
.
String
(
"arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567"
),
Tags
:
[]
*
resourcegroupstaggingapi
.
Tag
{
{
Key
:
aws
.
String
(
"Environment"
),
Value
:
aws
.
String
(
"production"
),
},
},
},
{
ResourceARN
:
aws
.
String
(
"arn:aws:ec2:us-east-1:123456789012:instance/i-76543210987654321"
),
Tags
:
[]
*
resourcegroupstaggingapi
.
Tag
{
{
Key
:
aws
.
String
(
"Environment"
),
Value
:
aws
.
String
(
"production"
),
},
},
},
},
},
},
}
json
:=
simplejson
.
New
()
json
.
Set
(
"region"
,
"us-east-1"
)
json
.
Set
(
"resourceType"
,
"ec2:instance"
)
tags
:=
make
(
map
[
string
]
interface
{})
tags
[
"Environment"
]
=
[]
string
{
"production"
}
json
.
Set
(
"tags"
,
tags
)
result
,
_
:=
executor
.
handleGetResourceArns
(
context
.
Background
(),
json
,
&
tsdb
.
TsdbQuery
{})
Convey
(
"Should return all two instances"
,
func
()
{
So
(
result
[
0
]
.
Text
,
ShouldEqual
,
"arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567"
)
So
(
result
[
0
]
.
Value
,
ShouldEqual
,
"arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567"
)
So
(
result
[
1
]
.
Text
,
ShouldEqual
,
"arn:aws:ec2:us-east-1:123456789012:instance/i-76543210987654321"
)
So
(
result
[
1
]
.
Value
,
ShouldEqual
,
"arn:aws:ec2:us-east-1:123456789012:instance/i-76543210987654321"
)
})
})
}
func
TestParseMultiSelectValue
(
t
*
testing
.
T
)
{
...
...
public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts
View file @
28aafcd7
...
...
@@ -380,6 +380,29 @@ describe('CloudWatchDatasource', () => {
});
});
describeMetricFindQuery
(
'resource_arns(default,ec2:instance,{"environment":["production"]})'
,
scenario
=>
{
scenario
.
setup
(()
=>
{
scenario
.
requestResponse
=
{
results
:
{
metricFindQuery
:
{
tables
:
[{
rows
:
[[
'arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567'
,
'arn:aws:ec2:us-east-1:123456789012:instance/i-76543210987654321'
]]
}],
},
},
};
});
it
(
'should call __ListMetrics and return result'
,
()
=>
{
expect
(
scenario
.
result
[
0
].
text
).
toContain
(
'arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567'
);
expect
(
scenario
.
request
.
queries
[
0
].
type
).
toBe
(
'metricFindQuery'
);
expect
(
scenario
.
request
.
queries
[
0
].
subtype
).
toBe
(
'resource_arns'
);
});
});
it
(
'should caclculate the correct period'
,
()
=>
{
const
hourSec
=
60
*
60
;
const
daySec
=
hourSec
*
24
;
...
...
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