github.com/assistd/afero@v1.1.1/path_test.go (about)

     1  // Copyright © 2014 Steve Francia <spf@spf13.com>.
     2  // Copyright 2009 The Go Authors. All rights reserved.
     3  //
     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
     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,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package afero
    16  
    17  import (
    18  	"fmt"
    19  	"os"
    20  	"testing"
    21  )
    22  
    23  func TestWalk(t *testing.T) {
    24  	defer removeAllTestFiles(t)
    25  	var testDir string
    26  	for i, fs := range Fss {
    27  		if i == 0 {
    28  			testDir = setupTestDirRoot(t, fs)
    29  		} else {
    30  			setupTestDirReusePath(t, fs, testDir)
    31  		}
    32  	}
    33  
    34  	outputs := make([]string, len(Fss))
    35  	for i, fs := range Fss {
    36  		walkFn := func(path string, info os.FileInfo, err error) error {
    37  			if err != nil {
    38  				t.Error("walkFn err:", err)
    39  			}
    40  			var size int64
    41  			if !info.IsDir() {
    42  				size = info.Size()
    43  			}
    44  			outputs[i] += fmt.Sprintln(path, info.Name(), size, info.IsDir(), err)
    45  			return nil
    46  		}
    47  		err := Walk(fs, testDir, walkFn)
    48  		if err != nil {
    49  			t.Error(err)
    50  		}
    51  	}
    52  	fail := false
    53  	for i, o := range outputs {
    54  		if i == 0 {
    55  			continue
    56  		}
    57  		if o != outputs[i-1] {
    58  			fail = true
    59  			break
    60  		}
    61  	}
    62  	if fail {
    63  		t.Log("Walk outputs not equal!")
    64  		for i, o := range outputs {
    65  			t.Log(Fss[i].Name() + "\n" + o)
    66  		}
    67  		t.Fail()
    68  	}
    69  }