lib/ur: Track new folder feature usage (#6803)

This commit is contained in:
Audrius Butkevicius
2020-06-28 20:35:22 +02:00
committed by GitHub
parent d7fc7008af
commit 9d4a700829
4 changed files with 180 additions and 6 deletions
+125
View File
@@ -287,3 +287,128 @@ func TestUtilStopTwicePanic(t *testing.T) {
}()
s.Stop()
}
func TestFillNil(t *testing.T) {
type A struct {
Slice []int
Map map[string]string
Chan chan int
}
type B struct {
Slice *[]int
Map *map[string]string
Chan *chan int
}
type C struct {
A A
B *B
D *****[]int
}
c := C{}
FillNil(&c)
if c.A.Slice == nil {
t.Error("c.A.Slice")
}
if c.A.Map == nil {
t.Error("c.A.Slice")
}
if c.A.Chan == nil {
t.Error("c.A.Chan")
}
if c.B == nil {
t.Error("c.B")
}
if c.B.Slice == nil {
t.Error("c.B.Slice")
}
if c.B.Map == nil {
t.Error("c.B.Slice")
}
if c.B.Chan == nil {
t.Error("c.B.Chan")
}
if *c.B.Slice == nil {
t.Error("*c.B.Slice")
}
if *c.B.Map == nil {
t.Error("*c.B.Slice")
}
if *c.B.Chan == nil {
t.Error("*c.B.Chan")
}
if *****c.D == nil {
t.Error("c.D")
}
}
func TestFillNilDoesNotBulldozeSetFields(t *testing.T) {
type A struct {
Slice []int
Map map[string]string
Chan chan int
}
type B struct {
Slice *[]int
Map *map[string]string
Chan *chan int
}
type C struct {
A A
B *B
D **[]int
}
ch := make(chan int, 10)
d := make([]int, 10)
dd := &d
c := C{
A: A{
Slice: []int{1},
Map: map[string]string{
"k": "v",
},
Chan: make(chan int, 10),
},
B: &B{
Slice: &[]int{1},
Map: &map[string]string{
"k": "v",
},
Chan: &ch,
},
D: &dd,
}
FillNil(&c)
if len(c.A.Slice) != 1 {
t.Error("c.A.Slice")
}
if len(c.A.Map) != 1 {
t.Error("c.A.Slice")
}
if cap(c.A.Chan) != 10 {
t.Error("c.A.Chan")
}
if c.B == nil {
t.Error("c.B")
}
if len(*c.B.Slice) != 1 {
t.Error("c.B.Slice")
}
if len(*c.B.Map) != 1 {
t.Error("c.B.Slice")
}
if cap(*c.B.Chan) != 10 {
t.Error("c.B.Chan")
}
if cap(**c.D) != 10 {
t.Error("c.D")
}
}