diff options
author | Corey Hulen <corey@hulen.com> | 2017-03-24 23:31:34 -0700 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-03-25 03:31:34 -0300 |
commit | 54d3d47daf9190275bbdaf8703b84969a4593451 (patch) | |
tree | 05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/github.com/spf13/afero/ro_regexp_test.go | |
parent | 7460302dec7796e01c98264e84bece8169cb6ed9 (diff) | |
download | chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2 chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip |
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes
* Removing the old fsnotify lib
* updating some missing libs
Diffstat (limited to 'vendor/github.com/spf13/afero/ro_regexp_test.go')
-rw-r--r-- | vendor/github.com/spf13/afero/ro_regexp_test.go | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/afero/ro_regexp_test.go b/vendor/github.com/spf13/afero/ro_regexp_test.go new file mode 100644 index 000000000..ef8a35d0d --- /dev/null +++ b/vendor/github.com/spf13/afero/ro_regexp_test.go @@ -0,0 +1,96 @@ +package afero + +import ( + "regexp" + "testing" +) + +func TestFilterReadOnly(t *testing.T) { + fs := &ReadOnlyFs{source: &MemMapFs{}} + _, err := fs.Create("/file.txt") + if err == nil { + t.Errorf("Did not fail to create file") + } + // t.Logf("ERR=%s", err) +} + +func TestFilterReadonlyRemoveAndRead(t *testing.T) { + mfs := &MemMapFs{} + fh, err := mfs.Create("/file.txt") + fh.Write([]byte("content here")) + fh.Close() + + fs := NewReadOnlyFs(mfs) + err = fs.Remove("/file.txt") + if err == nil { + t.Errorf("Did not fail to remove file") + } + + fh, err = fs.Open("/file.txt") + if err != nil { + t.Errorf("Failed to open file: %s", err) + } + + buf := make([]byte, len("content here")) + _, err = fh.Read(buf) + fh.Close() + if string(buf) != "content here" { + t.Errorf("Failed to read file: %s", err) + } + + err = mfs.Remove("/file.txt") + if err != nil { + t.Errorf("Failed to remove file") + } + + fh, err = fs.Open("/file.txt") + if err == nil { + fh.Close() + t.Errorf("File still present") + } +} + +func TestFilterRegexp(t *testing.T) { + fs := NewRegexpFs(&MemMapFs{}, regexp.MustCompile(`\.txt$`)) + _, err := fs.Create("/file.html") + if err == nil { + + t.Errorf("Did not fail to create file") + } + // t.Logf("ERR=%s", err) +} + +func TestFilterRORegexpChain(t *testing.T) { + rofs := &ReadOnlyFs{source: &MemMapFs{}} + fs := &RegexpFs{re: regexp.MustCompile(`\.txt$`), source: rofs} + _, err := fs.Create("/file.txt") + if err == nil { + t.Errorf("Did not fail to create file") + } + // t.Logf("ERR=%s", err) +} + +func TestFilterRegexReadDir(t *testing.T) { + mfs := &MemMapFs{} + fs1 := &RegexpFs{re: regexp.MustCompile(`\.txt$`), source: mfs} + fs := &RegexpFs{re: regexp.MustCompile(`^a`), source: fs1} + + mfs.MkdirAll("/dir/sub", 0777) + for _, name := range []string{"afile.txt", "afile.html", "bfile.txt"} { + for _, dir := range []string{"/dir/", "/dir/sub/"} { + fh, _ := mfs.Create(dir + name) + fh.Close() + } + } + + files, _ := ReadDir(fs, "/dir") + if len(files) != 2 { // afile.txt, sub + t.Errorf("Got wrong number of files: %#v", files) + } + + f, _ := fs.Open("/dir/sub") + names, _ := f.Readdirnames(-1) + if len(names) != 1 { + t.Errorf("Got wrong number of names: %v", names) + } +} |