...

Source file src/github.com/aws/aws-sdk-go-v2/internal/awstesting/util_test.go

Documentation: github.com/aws/aws-sdk-go-v2/internal/awstesting

     1  package awstesting_test
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go-v2/internal/awstesting"
     8  )
     9  
    10  func TestReadCloserClose(t *testing.T) {
    11  	rc := awstesting.ReadCloser{Size: 1}
    12  	err := rc.Close()
    13  
    14  	if err != nil {
    15  		t.Errorf("expect nil, got %v", err)
    16  	}
    17  	if !rc.Closed {
    18  		t.Errorf("expect closed, was not")
    19  	}
    20  	if e, a := rc.Size, 1; e != a {
    21  		t.Errorf("expect %v, got %v", e, a)
    22  	}
    23  }
    24  
    25  func TestReadCloserRead(t *testing.T) {
    26  	rc := awstesting.ReadCloser{Size: 5}
    27  	b := make([]byte, 2)
    28  
    29  	n, err := rc.Read(b)
    30  
    31  	if err != nil {
    32  		t.Errorf("expect nil, got %v", err)
    33  	}
    34  	if e, a := n, 2; e != a {
    35  		t.Errorf("expect %v, got %v", e, a)
    36  	}
    37  	if rc.Closed {
    38  		t.Errorf("expect not to be closed")
    39  	}
    40  	if e, a := rc.Size, 3; e != a {
    41  		t.Errorf("expect %v, got %v", e, a)
    42  	}
    43  
    44  	err = rc.Close()
    45  	if err != nil {
    46  		t.Errorf("expect nil, got %v", err)
    47  	}
    48  	n, err = rc.Read(b)
    49  	if e, a := err, io.EOF; e != a {
    50  		t.Errorf("expect %v, got %v", e, a)
    51  	}
    52  	if e, a := n, 0; e != a {
    53  		t.Errorf("expect %v, got %v", e, a)
    54  	}
    55  }
    56  
    57  func TestReadCloserReadAll(t *testing.T) {
    58  	rc := awstesting.ReadCloser{Size: 5}
    59  	b := make([]byte, 5)
    60  
    61  	n, err := rc.Read(b)
    62  
    63  	if e, a := err, io.EOF; e != a {
    64  		t.Errorf("expect %v, got %v", e, a)
    65  	}
    66  	if e, a := n, 5; e != a {
    67  		t.Errorf("expect %v, got %v", e, a)
    68  	}
    69  	if rc.Closed {
    70  		t.Errorf("expect not to be closed")
    71  	}
    72  	if e, a := rc.Size, 0; e != a {
    73  		t.Errorf("expect %v, got %v", e, a)
    74  	}
    75  }
    76  

View as plain text