aboutsummaryrefslogblamecommitdiffstats
path: root/utils/fs/os_test.go
blob: c1482657d69b11c86c360a11e183f2af83b21518 (plain) (tree)
1
2
3
4
5
6
7






                   




                                       
                          
 
                              
 


                                                  
 
                                      
                            
                                                                  

 


                                                 
 




                                        
 

                                                            

 


                                                 
 



                                      
 

                                                    

 


                                                                  
 
package fs

import (
	"io/ioutil"
	"os"
	"testing"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

type WritersSuite struct{}

var _ = Suite(&WritersSuite{})

func (s *WritersSuite) TestOSClient_Create(c *C) {
	path := getTempDir()
	client := NewOSClient(path)

	f, err := client.Create("foo")
	c.Assert(err, IsNil)
	c.Assert(f.(*OSFile).file.Name(), Equals, f.GetFilename())
}

func (s *WritersSuite) TestOSClient_Write(c *C) {
	path := getTempDir()
	client := NewOSClient(path)

	f, err := client.Create("foo")
	c.Assert(err, IsNil)
	l, err := f.Write([]byte("foo"))
	c.Assert(l, Equals, 3)
	c.Assert(err, IsNil)

	wrote, _ := ioutil.ReadFile(f.(*OSFile).file.Name())
	c.Assert(wrote, DeepEquals, []byte("foo"))
}

func (s *WritersSuite) TestOSClient_Close(c *C) {
	path := getTempDir()
	client := NewOSClient(path)

	f, err := client.Create("foo")
	c.Assert(err, IsNil)
	f.Write([]byte("foo"))
	c.Assert(f.Close(), IsNil)

	wrote, _ := ioutil.ReadFile(f.GetFilename())
	c.Assert(wrote, DeepEquals, []byte("foo"))
}

func getTempDir() string {
	dir, _ := ioutil.TempDir(os.TempDir(), "--OSClientTest--")
	return dir
}