Fix the dependency issue (#231)

This commit is contained in:
Robbie Zhang
2018-06-21 12:09:42 -07:00
committed by GitHub
parent 027b76651d
commit 6ec1098bb8
16629 changed files with 74837 additions and 4975021 deletions

View File

@@ -1,81 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
import (
"testing"
"time"
)
func TestAggregatorNoSinks(t *testing.T) {
ch := make(chan Report)
a := NewAggregator(dummySinker{ch})
a.Done()
_, ok := <-ch
if ok {
t.Errorf("Expected channel to be closed")
}
}
func TestAggregatorMultipleSinks(t *testing.T) {
ch := make(chan Report)
a := NewAggregator(dummySinker{ch})
for i := 0; i < 5; i++ {
go func(ch chan<- Report) {
ch <- dummyReport{}
ch <- dummyReport{}
close(ch)
}(a.Sink())
<-ch
<-ch
}
a.Done()
_, ok := <-ch
if ok {
t.Errorf("Expected channel to be closed")
}
}
func TestAggregatorSinkInFlightOnDone(t *testing.T) {
ch := make(chan Report)
a := NewAggregator(dummySinker{ch})
// Simulate upstream
go func(ch chan<- Report) {
time.Sleep(1 * time.Millisecond)
ch <- dummyReport{}
close(ch)
}(a.Sink())
// Drain downstream
go func(ch <-chan Report) {
<-ch
}(ch)
// This should wait for upstream to complete
a.Done()
_, ok := <-ch
if ok {
t.Errorf("Expected channel to be closed")
}
}

View File

@@ -1,43 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
type dummySinker struct {
ch chan Report
}
func (d dummySinker) Sink() chan<- Report {
return d.ch
}
type dummyReport struct {
p float32
d string
e error
}
func (p dummyReport) Percentage() float32 {
return p.p
}
func (p dummyReport) Detail() string {
return p.d
}
func (p dummyReport) Error() error {
return p.e
}

View File

@@ -1,40 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
import "testing"
func TestPrefix(t *testing.T) {
var r Report
ch := make(chan Report, 1)
s := Prefix(dummySinker{ch}, "prefix").Sink()
// No detail
s <- dummyReport{d: ""}
r = <-ch
if r.Detail() != "prefix" {
t.Errorf("Expected detail to be prefixed")
}
// With detail
s <- dummyReport{d: "something"}
r = <-ch
if r.Detail() != "prefix: something" {
t.Errorf("Expected detail to be prefixed")
}
}

View File

@@ -1,92 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
import (
"context"
"io"
"strings"
"testing"
)
func TestReader(t *testing.T) {
s := "helloworld"
ch := make(chan Report, 1)
pr := NewReader(context.Background(), &dummySinker{ch}, strings.NewReader(s), int64(len(s)))
var buf [10]byte
var q Report
var n int
var err error
// Read first byte
n, err = pr.Read(buf[0:1])
if n != 1 {
t.Errorf("Expected n=1, but got: %d", n)
}
if err != nil {
t.Errorf("Error: %s", err)
}
q = <-ch
if q.Error() != nil {
t.Errorf("Error: %s", err)
}
if f := q.Percentage(); f != 10.0 {
t.Errorf("Expected percentage after 1 byte to be 10%%, but got: %.0f%%", f)
}
// Read remaining bytes
n, err = pr.Read(buf[:])
if n != 9 {
t.Errorf("Expected n=1, but got: %d", n)
}
if err != nil {
t.Errorf("Error: %s", err)
}
q = <-ch
if q.Error() != nil {
t.Errorf("Error: %s", err)
}
if f := q.Percentage(); f != 100.0 {
t.Errorf("Expected percentage after 10 bytes to be 100%%, but got: %.0f%%", f)
}
// Read EOF
_, err = pr.Read(buf[:])
q = <-ch
if err != io.EOF {
t.Errorf("Expected io.EOF, but got: %s", err)
}
// Mark progress reader as done
pr.Done(io.EOF)
q = <-ch
if err != io.EOF {
t.Errorf("Expected io.EOF, but got: %s", err)
}
// Progress channel should be closed after progress reader is marked done
_, ok := <-ch
if ok {
t.Errorf("Expected channel to be closed")
}
}

View File

@@ -1,45 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
import "testing"
func TestScaleMany(t *testing.T) {
ch := make(chan Report)
a := NewAggregator(dummySinker{ch})
defer a.Done()
s := Scale(a, 5)
go func() {
for i := 0; i < 5; i++ {
go func(ch chan<- Report) {
ch <- dummyReport{p: 0.0}
ch <- dummyReport{p: 50.0}
close(ch)
}(s.Sink())
}
}()
// Expect percentages to be scaled across sinks
for p := float32(0.0); p < 100.0; p += 10.0 {
r := <-ch
if r.Percentage() != p {
t.Errorf("Expected percentage to be: %.0f%%", p)
}
}
}

View File

@@ -1,46 +0,0 @@
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package progress
import "testing"
func TestTee(t *testing.T) {
var ok bool
ch1 := make(chan Report)
ch2 := make(chan Report)
s := Tee(&dummySinker{ch: ch1}, &dummySinker{ch: ch2})
in := s.Sink()
in <- dummyReport{}
close(in)
// Receive dummy on both sinks
<-ch1
<-ch2
_, ok = <-ch1
if ok {
t.Errorf("Expected channel to be closed")
}
_, ok = <-ch2
if ok {
t.Errorf("Expected channel to be closed")
}
}