github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/os/fsi/tests/suite3_test.go (about)

     1  // +build suite3
     2  // go test -tags=suite3
     3  
     4  package tests
     5  
     6  // Copyright © 2014 Steve Francia <spf@spf13.com>.
     7  // Copyright 2009 The Go Authors. All rights reserved.
     8  //
     9  // Licensed under the Apache License, Version 2.0 (the "License");
    10  // you may not use this file except in compliance with the License.
    11  // You may obtain a copy of the License at
    12  // http://www.apache.org/licenses/LICENSE-2.0
    13  //
    14  // Unless required by applicable law or agreed to in writing, software
    15  // distributed under the License is distributed on an "AS IS" BASIS,
    16  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17  // See the License for the specific language governing permissions and
    18  // limitations under the License.
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/pbberlin/tools/os/fsi"
    24  )
    25  
    26  func TestRename(t *testing.T) {
    27  
    28  	Fss, c := initFileSystems()
    29  	defer c.Close()
    30  	for _, fs := range Fss {
    31  		from, to := testDir+"/renamefrom", testDir+"/renameto"
    32  		fs.Remove(to)              // Just in case.
    33  		fs.MkdirAll(testDir, 0777) // Just in case.
    34  		file, err := fs.Create(from)
    35  		if err != nil {
    36  			t.Fatalf("open %q failed: %v", to, err)
    37  		}
    38  		if err = file.Close(); err != nil {
    39  			t.Errorf("close %q failed: %v", to, err)
    40  		}
    41  		err = fs.Rename(from, to)
    42  		if err == fsi.NotImplemented {
    43  			continue
    44  		}
    45  		if err != nil {
    46  			t.Fatalf("rename %q, %q failed: %v", to, from, err)
    47  		}
    48  		defer fs.Remove(to)
    49  		_, err = fs.Stat(to)
    50  		if err != nil {
    51  			t.Errorf("stat %q failed: %v, %v", to, err, fs.Name())
    52  		}
    53  	}
    54  }