Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9df909a6
Commit
9df909a6
authored
Apr 16, 2019
by
Ben Fuller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "MicroTime/Time: remove pointer receivers and redundant IsZero() method"
This reverts commit
e129d701
. Co-authored-by:
David Timm
<
dtimm@pivotal.io
>
parent
e129d701
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
63 deletions
+180
-63
micro_time.go
...ng/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time.go
+34
-8
micro_time_test.go
...c/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time_test.go
+76
-34
time.go
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time.go
+21
-4
time_test.go
...ing/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go
+47
-15
apis_meta_v1_unstructed_unstructure_test.go
...nery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go
+2
-2
No files found.
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time.go
View file @
9df909a6
...
@@ -57,24 +57,50 @@ func NowMicro() MicroTime {
...
@@ -57,24 +57,50 @@ func NowMicro() MicroTime {
return
MicroTime
{
time
.
Now
()}
return
MicroTime
{
time
.
Now
()}
}
}
// IsZero returns true if the value is nil or time is zero.
func
(
t
*
MicroTime
)
IsZero
()
bool
{
if
t
==
nil
{
return
true
}
return
t
.
Time
.
IsZero
()
}
// Before reports whether the time instant t is before u.
// Before reports whether the time instant t is before u.
func
(
t
MicroTime
)
Before
(
u
MicroTime
)
bool
{
func
(
t
*
MicroTime
)
Before
(
u
*
MicroTime
)
bool
{
return
t
.
Time
.
Before
(
u
.
Time
)
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Before
(
u
.
Time
)
}
return
false
}
}
// Equal reports whether the time instant t is equal to u.
// Equal reports whether the time instant t is equal to u.
func
(
t
MicroTime
)
Equal
(
u
MicroTime
)
bool
{
func
(
t
*
MicroTime
)
Equal
(
u
*
MicroTime
)
bool
{
return
t
.
Time
.
Equal
(
u
.
Time
)
if
t
==
nil
&&
u
==
nil
{
return
true
}
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Equal
(
u
.
Time
)
}
return
false
}
}
// BeforeTime reports whether the time instant t is before second-lever precision u.
// BeforeTime reports whether the time instant t is before second-lever precision u.
func
(
t
MicroTime
)
BeforeTime
(
u
Time
)
bool
{
func
(
t
*
MicroTime
)
BeforeTime
(
u
*
Time
)
bool
{
return
t
.
Time
.
Before
(
u
.
Time
)
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Before
(
u
.
Time
)
}
return
false
}
}
// EqualTime reports whether the time instant t is equal to second-lever precision u.
// EqualTime reports whether the time instant t is equal to second-lever precision u.
func
(
t
MicroTime
)
EqualTime
(
u
Time
)
bool
{
func
(
t
*
MicroTime
)
EqualTime
(
u
*
Time
)
bool
{
return
t
.
Time
.
Equal
(
u
.
Time
)
if
t
==
nil
&&
u
==
nil
{
return
true
}
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Equal
(
u
.
Time
)
}
return
false
}
}
// UnixMicro returns the local time corresponding to the given Unix time
// UnixMicro returns the local time corresponding to the given Unix time
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time_test.go
View file @
9df909a6
...
@@ -140,73 +140,115 @@ func TestMicroTimeProto(t *testing.T) {
...
@@ -140,73 +140,115 @@ func TestMicroTimeProto(t *testing.T) {
func
TestMicroTimeEqual
(
t
*
testing
.
T
)
{
func
TestMicroTimeEqual
(
t
*
testing
.
T
)
{
t1
:=
NewMicroTime
(
time
.
Now
())
t1
:=
NewMicroTime
(
time
.
Now
())
t2
:=
NewMicroTime
(
time
.
Now
()
.
Add
(
time
.
Second
))
cases
:=
[]
struct
{
name
string
if
!
t1
.
Equal
(
t1
)
{
x
*
MicroTime
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should equal t1"
,
t1
,
t1
)
y
*
MicroTime
result
bool
}{
{
"nil =? nil"
,
nil
,
nil
,
true
},
{
"!nil =? !nil"
,
&
t1
,
&
t1
,
true
},
{
"nil =? !nil"
,
nil
,
&
t1
,
false
},
{
"!nil =? nil"
,
&
t1
,
nil
,
false
},
}
}
if
t1
.
Equal
(
t2
)
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should not equal t2"
,
t1
,
t2
)
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
Equal
(
c
.
y
)
if
result
!=
c
.
result
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
}
})
}
}
}
}
func
TestMicroTimeEqualTime
(
t
*
testing
.
T
)
{
func
TestMicroTimeEqualTime
(
t
*
testing
.
T
)
{
t1
:=
NewMicroTime
(
time
.
Now
())
t1
:=
NewMicroTime
(
time
.
Now
())
t2
:=
NewTime
(
t1
.
Time
)
t2
:=
NewTime
(
t1
.
Time
)
t3
:=
NewTime
(
time
.
Now
()
.
Add
(
time
.
Second
))
cases
:=
[]
struct
{
name
string
if
!
t1
.
EqualTime
(
t2
)
{
x
*
MicroTime
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should equal t2"
,
t1
,
t1
)
y
*
Time
result
bool
}{
{
"nil =? nil"
,
nil
,
nil
,
true
},
{
"!nil =? !nil"
,
&
t1
,
&
t2
,
true
},
{
"nil =? !nil"
,
nil
,
&
t2
,
false
},
{
"!nil =? nil"
,
&
t1
,
nil
,
false
},
}
}
if
t1
.
EqualTime
(
t3
)
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should not equal t3"
,
t1
,
t2
)
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
EqualTime
(
c
.
y
)
if
result
!=
c
.
result
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
}
})
}
}
}
}
func
TestMicroTimeBefore
(
t
*
testing
.
T
)
{
func
TestMicroTimeBefore
(
t
*
testing
.
T
)
{
tBefore
:=
NewMicroTime
(
time
.
Now
())
t1
:=
NewMicroTime
(
time
.
Now
())
tAfter
:=
NewMicroTime
(
tBefore
.
Time
.
Add
(
time
.
Second
))
cases
:=
[]
struct
{
cases
:=
[]
struct
{
name
string
name
string
x
MicroTime
x
*
MicroTime
y
MicroTime
y
*
MicroTime
result
bool
}{
}{
{
"tBefore <? tBefore"
,
tBefore
,
tBefore
,
false
},
{
"nil <? nil"
,
nil
,
nil
},
{
"tBefore <? tAfter"
,
tBefore
,
tAfter
,
true
},
{
"!nil <? !nil"
,
&
t1
,
&
t1
},
{
"tAfter <? tBefore"
,
tAfter
,
tBefore
,
false
},
{
"nil <? !nil"
,
nil
,
&
t1
},
{
"!nil <? nil"
,
&
t1
,
nil
},
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
Before
(
c
.
y
)
result
:=
c
.
x
.
Before
(
c
.
y
)
if
result
!=
c
.
result
{
if
result
{
t
.
Errorf
(
"Failed before test for '%v', '%v': expected
%+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
t
.
Errorf
(
"Failed before test for '%v', '%v': expected
false, got %+v"
,
c
.
x
,
c
.
y
,
result
)
}
}
})
})
}
}
}
}
func
TestMicroTimeBeforeTime
(
t
*
testing
.
T
)
{
func
TestMicroTimeBeforeTime
(
t
*
testing
.
T
)
{
tNow
:=
NewMicroTime
(
time
.
Now
())
t1
:=
NewMicroTime
(
time
.
Now
())
tAfter
:=
NewTime
(
tNow
.
Time
.
Add
(
time
.
Second
))
t2
:=
NewTime
(
t1
.
Time
)
tBefore
:=
NewTime
(
tNow
.
Time
.
Add
(
-
time
.
Second
))
cases
:=
[]
struct
{
tTimeNow
:=
NewTime
(
tNow
.
Time
)
name
string
x
*
MicroTime
y
*
Time
}{
{
"nil <? nil"
,
nil
,
nil
},
{
"!nil <? !nil"
,
&
t1
,
&
t2
},
{
"nil <? !nil"
,
nil
,
&
t2
},
{
"!nil <? nil"
,
&
t1
,
nil
},
}
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
BeforeTime
(
c
.
y
)
if
result
{
t
.
Errorf
(
"Failed before test for '%v', '%v': expected false, got %+v"
,
c
.
x
,
c
.
y
,
result
)
}
})
}
}
func
TestMicroTimeIsZero
(
t
*
testing
.
T
)
{
t1
:=
NewMicroTime
(
time
.
Now
())
cases
:=
[]
struct
{
cases
:=
[]
struct
{
name
string
name
string
x
MicroTime
x
*
MicroTime
y
Time
result
bool
result
bool
}{
}{
{
"tNow <? tAfter"
,
tNow
,
tAfter
,
true
},
{
"nil =? 0"
,
nil
,
true
},
{
"tNow <? tBefore"
,
tNow
,
tBefore
,
false
},
{
"!nil =? 0"
,
&
t1
,
false
},
{
"tNow <? tTimeNow"
,
tNow
,
tTimeNow
,
false
},
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
BeforeTime
(
c
.
y
)
result
:=
c
.
x
.
IsZero
(
)
if
result
!=
c
.
result
{
if
result
!=
c
.
result
{
t
.
Errorf
(
"Failed
before test for '%v', '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
t
.
Errorf
(
"Failed
equality test for '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
result
,
result
)
}
}
})
})
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time.go
View file @
9df909a6
...
@@ -57,14 +57,31 @@ func Now() Time {
...
@@ -57,14 +57,31 @@ func Now() Time {
return
Time
{
time
.
Now
()}
return
Time
{
time
.
Now
()}
}
}
// IsZero returns true if the value is nil or time is zero.
func
(
t
*
Time
)
IsZero
()
bool
{
if
t
==
nil
{
return
true
}
return
t
.
Time
.
IsZero
()
}
// Before reports whether the time instant t is before u.
// Before reports whether the time instant t is before u.
func
(
t
Time
)
Before
(
u
Time
)
bool
{
func
(
t
*
Time
)
Before
(
u
*
Time
)
bool
{
return
t
.
Time
.
Before
(
u
.
Time
)
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Before
(
u
.
Time
)
}
return
false
}
}
// Equal reports whether the time instant t is equal to u.
// Equal reports whether the time instant t is equal to u.
func
(
t
Time
)
Equal
(
u
Time
)
bool
{
func
(
t
*
Time
)
Equal
(
u
*
Time
)
bool
{
return
t
.
Time
.
Equal
(
u
.
Time
)
if
t
==
nil
&&
u
==
nil
{
return
true
}
if
t
!=
nil
&&
u
!=
nil
{
return
t
.
Time
.
Equal
(
u
.
Time
)
}
return
false
}
}
// Unix returns the local time corresponding to the given Unix time
// Unix returns the local time corresponding to the given Unix time
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go
View file @
9df909a6
...
@@ -174,35 +174,67 @@ func TestTimeProto(t *testing.T) {
...
@@ -174,35 +174,67 @@ func TestTimeProto(t *testing.T) {
func
TestTimeEqual
(
t
*
testing
.
T
)
{
func
TestTimeEqual
(
t
*
testing
.
T
)
{
t1
:=
NewTime
(
time
.
Now
())
t1
:=
NewTime
(
time
.
Now
())
t2
:=
NewTime
(
time
.
Now
()
.
Add
(
time
.
Second
))
cases
:=
[]
struct
{
name
string
if
!
t1
.
Equal
(
t1
)
{
x
*
Time
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should equal t1"
,
t1
,
t1
)
y
*
Time
result
bool
}{
{
"nil =? nil"
,
nil
,
nil
,
true
},
{
"!nil =? !nil"
,
&
t1
,
&
t1
,
true
},
{
"nil =? !nil"
,
nil
,
&
t1
,
false
},
{
"!nil =? nil"
,
&
t1
,
nil
,
false
},
}
}
if
t1
.
Equal
(
t2
)
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': t1 should not equal t2"
,
t1
,
t2
)
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
Equal
(
c
.
y
)
if
result
!=
c
.
result
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
}
})
}
}
}
}
func
TestTimeBefore
(
t
*
testing
.
T
)
{
func
TestTimeBefore
(
t
*
testing
.
T
)
{
tBefore
:=
NewTime
(
time
.
Now
())
t1
:=
NewTime
(
time
.
Now
())
tAfter
:=
NewTime
(
tBefore
.
Time
.
Add
(
time
.
Second
))
cases
:=
[]
struct
{
name
string
x
*
Time
y
*
Time
}{
{
"nil <? nil"
,
nil
,
nil
},
{
"!nil <? !nil"
,
&
t1
,
&
t1
},
{
"nil <? !nil"
,
nil
,
&
t1
},
{
"!nil <? nil"
,
&
t1
,
nil
},
}
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
Before
(
c
.
y
)
if
result
{
t
.
Errorf
(
"Failed equality test for '%v', '%v': expected false, got %+v"
,
c
.
x
,
c
.
y
,
result
)
}
})
}
}
func
TestTimeIsZero
(
t
*
testing
.
T
)
{
t1
:=
NewTime
(
time
.
Now
())
cases
:=
[]
struct
{
cases
:=
[]
struct
{
name
string
name
string
x
Time
x
*
Time
y
Time
result
bool
result
bool
}{
}{
{
"tBefore <? tBefore"
,
tBefore
,
tBefore
,
false
},
{
"nil =? 0"
,
nil
,
true
},
{
"tBefore <? tAfter"
,
tBefore
,
tAfter
,
true
},
{
"!nil =? 0"
,
&
t1
,
false
},
{
"tAfter <? tBefore"
,
tAfter
,
tBefore
,
false
},
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
c
.
name
,
func
(
t
*
testing
.
T
)
{
result
:=
c
.
x
.
Before
(
c
.
y
)
result
:=
c
.
x
.
IsZero
(
)
if
result
!=
c
.
result
{
if
result
!=
c
.
result
{
t
.
Errorf
(
"Failed
before test for '%v', '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
y
,
c
.
result
,
result
)
t
.
Errorf
(
"Failed
equality test for '%v': expected %+v, got %+v"
,
c
.
x
,
c
.
result
,
result
)
}
}
})
})
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go
View file @
9df909a6
...
@@ -207,11 +207,11 @@ func TestUnstructuredGetters(t *testing.T) {
...
@@ -207,11 +207,11 @@ func TestUnstructuredGetters(t *testing.T) {
t
.
Errorf
(
"GetSelfLink() = %s, want %s"
,
got
,
want
)
t
.
Errorf
(
"GetSelfLink() = %s, want %s"
,
got
,
want
)
}
}
if
got
,
want
:=
unstruct
.
GetCreationTimestamp
(),
metav1
.
Date
(
2009
,
time
.
November
,
10
,
23
,
0
,
0
,
0
,
time
.
UTC
);
!
got
.
Equal
(
want
)
{
if
got
,
want
:=
unstruct
.
GetCreationTimestamp
(),
metav1
.
Date
(
2009
,
time
.
November
,
10
,
23
,
0
,
0
,
0
,
time
.
UTC
);
!
got
.
Equal
(
&
want
)
{
t
.
Errorf
(
"GetCreationTimestamp() = %s, want %s"
,
got
,
want
)
t
.
Errorf
(
"GetCreationTimestamp() = %s, want %s"
,
got
,
want
)
}
}
if
got
,
want
:=
unstruct
.
GetDeletionTimestamp
(),
metav1
.
Date
(
2010
,
time
.
November
,
10
,
23
,
0
,
0
,
0
,
time
.
UTC
);
got
==
nil
||
!
got
.
Equal
(
want
)
{
if
got
,
want
:=
unstruct
.
GetDeletionTimestamp
(),
metav1
.
Date
(
2010
,
time
.
November
,
10
,
23
,
0
,
0
,
0
,
time
.
UTC
);
got
==
nil
||
!
got
.
Equal
(
&
want
)
{
t
.
Errorf
(
"GetDeletionTimestamp() = %s, want %s"
,
got
,
want
)
t
.
Errorf
(
"GetDeletionTimestamp() = %s, want %s"
,
got
,
want
)
}
}
...
...
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