...

Source file src/github.com/docker/distribution/registry/storage/driver/walk_test.go

Documentation: github.com/docker/distribution/registry/storage/driver

     1  package driver
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  )
     8  
     9  type changingFileSystem struct {
    10  	StorageDriver
    11  	fileset   []string
    12  	keptFiles map[string]bool
    13  }
    14  
    15  func (cfs *changingFileSystem) List(ctx context.Context, path string) ([]string, error) {
    16  	return cfs.fileset, nil
    17  }
    18  func (cfs *changingFileSystem) Stat(ctx context.Context, path string) (FileInfo, error) {
    19  	kept, ok := cfs.keptFiles[path]
    20  	if ok && kept {
    21  		return &FileInfoInternal{
    22  			FileInfoFields: FileInfoFields{
    23  				Path: path,
    24  			},
    25  		}, nil
    26  	}
    27  	return nil, PathNotFoundError{}
    28  }
    29  func TestWalkFileRemoved(t *testing.T) {
    30  	d := &changingFileSystem{
    31  		fileset: []string{"zoidberg", "bender"},
    32  		keptFiles: map[string]bool{
    33  			"zoidberg": true,
    34  		},
    35  	}
    36  	infos := []FileInfo{}
    37  	err := WalkFallback(context.Background(), d, "", func(fileInfo FileInfo) error {
    38  		infos = append(infos, fileInfo)
    39  		return nil
    40  	})
    41  	if len(infos) != 1 || infos[0].Path() != "zoidberg" {
    42  		t.Errorf(fmt.Sprintf("unexpected path set during walk: %s", infos))
    43  	}
    44  	if err != nil {
    45  		t.Fatalf(err.Error())
    46  	}
    47  }
    48  

View as plain text