github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/Unknwon/cae/tz/stream_test.go (about)

     1  // Copyright 2014 Unknown
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package tz
    16  
    17  import (
    18  	"os"
    19  	"path"
    20  	"testing"
    21  
    22  	. "github.com/insionng/yougam/libraries/smartystreets/goconvey/convey"
    23  )
    24  
    25  func TestStream(t *testing.T) {
    26  	Convey("Create a stream archive", t, func() {
    27  		fw, err := os.Create(path.Join(os.TempDir(), "testdata/TestStream.tar.gz"))
    28  		So(err, ShouldBeNil)
    29  		s := NewStreamArachive(fw)
    30  
    31  		Convey("Stream a file", func() {
    32  			f, err := os.Open("testdata/gophercolor16x16.png")
    33  			So(err, ShouldBeNil)
    34  
    35  			fi, err := f.Stat()
    36  			So(err, ShouldBeNil)
    37  
    38  			data := make([]byte, fi.Size())
    39  			_, err = f.Read(data)
    40  			So(err, ShouldBeNil)
    41  
    42  			So(s.StreamFile("", fi, data), ShouldBeNil)
    43  		})
    44  
    45  		Convey("Stream a file with type directory", func() {
    46  			f, err := os.Open("testdata")
    47  			So(err, ShouldBeNil)
    48  
    49  			fi, err := f.Stat()
    50  			So(err, ShouldBeNil)
    51  
    52  			So(s.StreamFile("", fi, nil), ShouldBeNil)
    53  		})
    54  
    55  		Convey("Stream a reader", func() {
    56  			f, err := os.Open("testdata/gophercolor16x16.png")
    57  			So(err, ShouldBeNil)
    58  
    59  			fi, err := f.Stat()
    60  			So(err, ShouldBeNil)
    61  
    62  			So(s.StreamReader("", fi, f), ShouldBeNil)
    63  		})
    64  	})
    65  }