Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Go
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kovrizhnyh dmitrij
Go
Commits
d622292d
Commit
d622292d
authored
1 year ago
by
kovrizhnyh dmitrij
Browse files
Options
Downloads
Patches
Plain Diff
Update assertions.go
parent
d6af79a2
Branches
master
No related merge requests found
Pipeline
#186347
failed with stage
in 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testequal/assertions.go
+4
-99
4 additions, 99 deletions
testequal/assertions.go
with
4 additions
and
99 deletions
testequal/assertions.go
+
4
−
99
View file @
d622292d
...
...
@@ -2,92 +2,13 @@
package
testequal
import
(
"bytes"
"fmt"
"reflect"
)
func
equal
(
expected
,
actual
interface
{})
bool
{
if
expected
==
nil
||
actual
==
nil
{
return
expected
==
actual
}
switch
v
:=
expected
.
(
type
)
{
case
uint
,
int
,
uint8
,
int8
,
uint16
,
int16
,
uint64
,
int64
:
return
v
==
actual
case
struct
{}
:
return
false
case
map
[
string
]
string
:
a
,
ok
:=
actual
.
(
map
[
string
]
string
)
if
!
ok
{
return
false
}
if
len
(
v
)
!=
len
(
a
)
{
return
false
}
if
len
(
a
)
==
0
{
return
false
}
for
key
,
val
:=
range
v
{
aval
,
ok
:=
a
[
key
]
if
!
ok
||
val
!=
aval
{
return
false
}
}
return
true
}
exp
,
ok
:=
expected
.
([]
byte
)
if
!
ok
{
return
reflect
.
DeepEqual
(
expected
,
actual
)
}
act
,
ok
:=
actual
.
([]
byte
)
if
!
ok
{
return
false
}
if
exp
==
nil
||
act
==
nil
{
return
exp
==
nil
&&
act
==
nil
}
return
bytes
.
Equal
(
exp
,
act
)
}
func
errorf
(
t
T
,
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
{
t
.
Helper
()
format
:=
`
expected: %v
actual : %v
message : %v`
msg
:=
``
l
:=
len
(
msgAndArgs
)
switch
l
{
case
0
:
break
case
1
:
msg
=
msgAndArgs
[
0
]
.
(
string
)
default
:
msg
=
fmt
.
Sprintf
(
msgAndArgs
[
0
]
.
(
string
),
msgAndArgs
[
1
:
]
...
)
}
t
.
Errorf
(
format
,
expected
,
actual
,
msg
)
}
// AssertEqual checks that expected and actual are equal.
//
// Marks caller function as having failed but continues execution.
//
// Returns true iff arguments are equal.
func
AssertEqual
(
t
T
,
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
t
.
Helper
()
if
equal
(
expected
,
actual
)
{
return
true
}
errorf
(
t
,
expected
,
actual
,
msgAndArgs
...
)
return
false
panic
(
"implement me"
)
}
// AssertNotEqual checks that expected and actual are not equal.
...
...
@@ -96,31 +17,15 @@ func AssertEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) b
//
// Returns true iff arguments are not equal.
func
AssertNotEqual
(
t
T
,
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
t
.
Helper
()
if
!
equal
(
expected
,
actual
)
{
return
true
}
errorf
(
t
,
expected
,
actual
,
msgAndArgs
...
)
return
false
panic
(
"implement me"
)
}
// RequireEqual does the same as AssertEqual but fails caller test immediately.
func
RequireEqual
(
t
T
,
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
{
t
.
Helper
()
if
equal
(
expected
,
actual
)
{
return
}
errorf
(
t
,
expected
,
actual
,
msgAndArgs
...
)
t
.
FailNow
()
panic
(
"implement me"
)
}
// RequireNotEqual does the same as AssertNotEqual but fails caller test immediately.
func
RequireNotEqual
(
t
T
,
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
{
t
.
Helper
()
if
!
equal
(
expected
,
actual
)
{
return
}
errorf
(
t
,
expected
,
actual
,
msgAndArgs
...
)
t
.
FailNow
()
panic
(
"implement me"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment