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
035be6cb
Commit
035be6cb
authored
Oct 02, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: add more tests
parent
68332c59
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
6 deletions
+50
-6
pkg/tsdb/stackdriver/stackdriver.go
+6
-6
pkg/tsdb/stackdriver/stackdriver_test.go
+44
-0
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
035be6cb
...
...
@@ -171,18 +171,18 @@ func reverse(s string) string {
func
interpolateFilterWildcards
(
value
string
)
string
{
re
:=
regexp
.
MustCompile
(
"[*]"
)
matches
:=
re
.
FindAllStringIndex
(
value
,
-
1
)
logger
.
Info
(
"len"
,
"len"
,
len
(
matches
)
)
if
len
(
matches
)
==
2
&&
strings
.
HasSuffix
(
value
,
"*"
)
&&
strings
.
HasPrefix
(
value
,
"*"
)
{
matches
:=
len
(
re
.
FindAllStringIndex
(
value
,
-
1
)
)
logger
.
Info
(
"len"
,
"len"
,
matches
)
if
matches
==
2
&&
strings
.
HasSuffix
(
value
,
"*"
)
&&
strings
.
HasPrefix
(
value
,
"*"
)
{
value
=
strings
.
Replace
(
value
,
"*"
,
""
,
-
1
)
value
=
fmt
.
Sprintf
(
`has_substring("%s")`
,
value
)
}
else
if
strings
.
HasPrefix
(
value
,
"*"
)
{
}
else
if
matches
==
1
&&
strings
.
HasPrefix
(
value
,
"*"
)
{
value
=
strings
.
Replace
(
value
,
"*"
,
""
,
1
)
value
=
fmt
.
Sprintf
(
`ends_with("%s")`
,
value
)
}
else
if
strings
.
HasSuffix
(
value
,
"*"
)
{
}
else
if
matches
==
1
&&
strings
.
HasSuffix
(
value
,
"*"
)
{
value
=
reverse
(
strings
.
Replace
(
reverse
(
value
),
"*"
,
""
,
1
))
value
=
fmt
.
Sprintf
(
`starts_with("%s")`
,
value
)
}
else
if
strings
.
Contains
(
value
,
"*"
)
{
}
else
if
matches
==
1
{
re
:=
regexp
.
MustCompile
(
`[-\/^$+?.()|[\]{}]`
)
value
=
string
(
re
.
ReplaceAllFunc
([]
byte
(
value
),
func
(
in
[]
byte
)
[]
byte
{
return
[]
byte
(
strings
.
Replace
(
string
(
in
),
string
(
in
),
`\\`
+
string
(
in
),
1
))
...
...
pkg/tsdb/stackdriver/stackdriver_test.go
View file @
035be6cb
...
...
@@ -354,6 +354,50 @@ func TestStackdriver(t *testing.T) {
So
(
value
,
ShouldNotStartWith
,
`has_substring`
)
})
})
Convey
(
"and wildcard is used in the beginning of the word"
,
func
()
{
Convey
(
"and there is not a wildcard elsewhere in the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"*-central1"
)
So
(
value
,
ShouldEqual
,
`ends_with("-central1")`
)
})
Convey
(
"and there is a wildcard elsewhere in the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"*-cent*al1"
)
So
(
value
,
ShouldNotStartWith
,
`ends_with`
)
})
})
Convey
(
"and wildcard is used at the end of the word"
,
func
()
{
Convey
(
"and there is not a wildcard elsewhere in the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"us-central*"
)
So
(
value
,
ShouldEqual
,
`starts_with("us-central")`
)
})
Convey
(
"and there is a wildcard elsewhere in the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"*us-central*"
)
So
(
value
,
ShouldNotStartWith
,
`starts_with`
)
})
})
Convey
(
"and wildcard is used in the middle of the word"
,
func
()
{
Convey
(
"and there is only one wildcard"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"us-ce*tral1-b"
)
So
(
value
,
ShouldEqual
,
`monitoring.regex.full_match("^us\\-ce.*tral1\\-b$")`
)
})
Convey
(
"and there is more than one wildcard"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"us-ce*tra*1-b"
)
So
(
value
,
ShouldEqual
,
`monitoring.regex.full_match("^us\\-ce.*tra.*1\\-b$")`
)
})
})
Convey
(
"and wildcard is used in the middle of the word and in the beginning of the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"*s-ce*tral1-b"
)
So
(
value
,
ShouldEqual
,
`monitoring.regex.full_match("^.*s\\-ce.*tral1\\-b$")`
)
})
Convey
(
"and wildcard is used in the middle of the word and in the ending of the word"
,
func
()
{
value
:=
interpolateFilterWildcards
(
"us-ce*tral1-*"
)
So
(
value
,
ShouldEqual
,
`monitoring.regex.full_match("^us\\-ce.*tral1\\-.*$")`
)
})
})
})
}
...
...
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