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
d2b3bcf3
Unverified
Commit
d2b3bcf3
authored
Jan 05, 2021
by
Emil Hessman
Committed by
GitHub
Jan 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite models tags test to standard library (#30041)
parent
a99edd2f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
79 deletions
+80
-79
pkg/models/tags_test.go
+80
-79
No files found.
pkg/models/tags_test.go
View file @
d2b3bcf3
...
...
@@ -3,93 +3,94 @@ package models
import
(
"testing"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestParsingTags
(
t
*
testing
.
T
)
{
Convey
(
"Testing parsing a tag pairs into tags"
,
t
,
func
()
{
Convey
(
"Can parse one empty tag"
,
func
()
{
tags
:=
ParseTagPairs
([]
string
{
""
})
So
(
len
(
tags
),
ShouldEqual
,
0
)
})
func
TestParseTagPairs
(
t
*
testing
.
T
)
{
t
.
Run
(
"Can parse one empty tag"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
""
})
require
.
Empty
(
t
,
tags
)
})
Convey
(
"Can parse valid tags"
,
func
(
)
{
tags
:=
ParseTagPairs
([]
string
{
"outage"
,
"type:outage"
,
"error"
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"outage"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"type"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"outage"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"error"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
""
)
})
t
.
Run
(
"Can parse valid tags"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
"outage"
,
"type:outage"
,
"error"
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"type"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"error"
,
tags
[
2
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
2
]
.
Value
)
})
Convey
(
"Can parse tags with spaces"
,
func
(
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage "
,
" type : outage "
,
"error "
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"outage"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"type"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"outage"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"error"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
""
)
})
t
.
Run
(
"Can parse tags with spaces"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage "
,
" type : outage "
,
"error "
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"type"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"error"
,
tags
[
2
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
2
]
.
Value
)
})
Convey
(
"Can parse empty tags"
,
func
(
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage "
,
""
,
""
,
":"
,
"type : outage "
,
"error "
,
""
,
""
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"outage"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"type"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"outage"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"error"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
""
)
})
t
.
Run
(
"Can parse empty tags"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage "
,
""
,
""
,
":"
,
"type : outage "
,
"error "
,
""
,
""
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"type"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"error"
,
tags
[
2
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
2
]
.
Value
)
})
Convey
(
"Can parse tags with extra colons"
,
func
(
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage"
,
"type : outage:outage2 :outage3 "
,
"error :"
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"outage"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"type"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"outage"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"error"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
""
)
})
t
.
Run
(
"Can parse tags with extra colons"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage"
,
"type : outage:outage2 :outage3 "
,
"error :"
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"type"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"outage"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"error"
,
tags
[
2
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
2
]
.
Value
)
})
Convey
(
"Can parse tags that contains key and values with spaces"
,
func
(
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage 1"
,
"type 1: outage 1 "
,
"has error "
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"outage 1"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"type 1"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"outage 1"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"has error"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
""
)
})
t
.
Run
(
"Can parse tags that contains key and values with spaces"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
" outage 1"
,
"type 1: outage 1 "
,
"has error "
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"outage 1"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"type 1"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"outage 1"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"has error"
,
tags
[
2
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
2
]
.
Value
)
})
Convey
(
"Can filter out duplicate tags"
,
func
()
{
tags
:=
ParseTagPairs
([]
string
{
"test"
,
"test"
,
"key:val1"
,
"key:val2"
})
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
]
.
Key
,
ShouldEqual
,
"test"
)
So
(
tags
[
0
]
.
Value
,
ShouldEqual
,
""
)
So
(
tags
[
1
]
.
Key
,
ShouldEqual
,
"key"
)
So
(
tags
[
1
]
.
Value
,
ShouldEqual
,
"val1"
)
So
(
tags
[
2
]
.
Key
,
ShouldEqual
,
"key"
)
So
(
tags
[
2
]
.
Value
,
ShouldEqual
,
"val2"
)
})
t
.
Run
(
"Can filter out duplicate tags"
,
func
(
t
*
testing
.
T
)
{
tags
:=
ParseTagPairs
([]
string
{
"test"
,
"test"
,
"key:val1"
,
"key:val2"
})
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"test"
,
tags
[
0
]
.
Key
)
assert
.
Empty
(
t
,
tags
[
0
]
.
Value
)
assert
.
Equal
(
t
,
"key"
,
tags
[
1
]
.
Key
)
assert
.
Equal
(
t
,
"val1"
,
tags
[
1
]
.
Value
)
assert
.
Equal
(
t
,
"key"
,
tags
[
2
]
.
Key
)
assert
.
Equal
(
t
,
"val2"
,
tags
[
2
]
.
Value
)
})
}
Convey
(
"Can join tag pairs"
,
func
(
)
{
tagPairs
:=
[]
*
Tag
{
{
Key
:
"key1"
,
Value
:
"val1"
},
{
Key
:
"key2"
,
Value
:
"
"
},
{
Key
:
"key3
"
},
}
tags
:=
JoinTagPairs
(
tagPairs
)
So
(
len
(
tags
),
ShouldEqual
,
3
)
So
(
tags
[
0
],
ShouldEqual
,
"key1:val1"
)
So
(
tags
[
1
],
ShouldEqual
,
"key2"
)
So
(
tags
[
2
],
ShouldEqual
,
"key3"
)
}
)
func
TestJoinTagPairs
(
t
*
testing
.
T
)
{
t
.
Run
(
"Can join tag pairs"
,
func
(
t
*
testing
.
T
)
{
tagPairs
:=
[]
*
Tag
{
{
Key
:
"key1"
,
Value
:
"val1
"
},
{
Key
:
"key2"
,
Value
:
"
"
},
{
Key
:
"key3"
},
}
tags
:=
JoinTagPairs
(
tagPairs
)
require
.
Len
(
t
,
tags
,
3
)
assert
.
Equal
(
t
,
"key1:val1"
,
tags
[
0
]
)
assert
.
Equal
(
t
,
"key2"
,
tags
[
1
]
)
assert
.
Equal
(
t
,
"key3"
,
tags
[
2
]
)
})
}
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