2
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
8
http://www.apache.org/licenses/LICENSE-2.0
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
25
func TestReader(t *testing.T) {
27
ch := make(chan Report, 1)
28
pr := NewReader(&dummySinker{ch}, strings.NewReader(s), int64(len(s)))
36
n, err = pr.Read(buf[0:1])
38
t.Errorf("Expected n=1, but got: %d", n)
42
t.Errorf("Error: %s", err)
47
t.Errorf("Error: %s", err)
50
if f := q.Percentage(); f != 10.0 {
51
t.Errorf("Expected percentage after 1 byte to be 10%%, but got: %.0f%%", f)
54
// Read remaining bytes
55
n, err = pr.Read(buf[:])
57
t.Errorf("Expected n=1, but got: %d", n)
60
t.Errorf("Error: %s", err)
65
t.Errorf("Error: %s", err)
68
if f := q.Percentage(); f != 100.0 {
69
t.Errorf("Expected percentage after 10 bytes to be 100%%, but got: %.0f%%", f)
73
_, err = pr.Read(buf[:])
75
t.Errorf("Expected io.EOF, but got: %s", err)
78
// Mark progress reader as done
82
t.Errorf("Expected io.EOF, but got: %s", err)
85
// Progress channel should be closed after progress reader is marked done
88
t.Errorf("Expected channel to be closed")