...

Source file src/github.com/redhat-developer/odo/pkg/testingutil/filesystem/filesystem.go

Documentation: github.com/redhat-developer/odo/pkg/testingutil/filesystem

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     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  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  /*
    18  	This package is a FORK of https://github.com/kubernetes/kubernetes/blob/master/pkg/util/filesystem/filesystem.go
    19  	See above license
    20  */
    21  
    22  package filesystem
    23  
    24  import (
    25  	"os"
    26  	"path/filepath"
    27  	"time"
    28  )
    29  
    30  // Filesystem is an interface that we can use to mock various filesystem operations
    31  type Filesystem interface {
    32  	// from "os"
    33  	Stat(name string) (os.FileInfo, error)
    34  	Create(name string) (File, error)
    35  	Open(name string) (File, error)
    36  	OpenFile(name string, flag int, perm os.FileMode) (File, error)
    37  	Rename(oldpath, newpath string) error
    38  	MkdirAll(path string, perm os.FileMode) error
    39  	Chtimes(name string, atime time.Time, mtime time.Time) error
    40  	RemoveAll(path string) error
    41  	Remove(name string) error
    42  	Chmod(name string, mode os.FileMode) error
    43  	Getwd() (dir string, err error)
    44  
    45  	// from "io/ioutil"
    46  	ReadFile(filename string) ([]byte, error)
    47  	WriteFile(filename string, data []byte, perm os.FileMode) error
    48  	TempDir(dir, prefix string) (string, error)
    49  	TempFile(dir, prefix string) (File, error)
    50  	ReadDir(dirname string) ([]os.FileInfo, error)
    51  	Walk(root string, walkFn filepath.WalkFunc) error
    52  }
    53  
    54  // File is an interface that we can use to mock various filesystem operations typically
    55  // accessed through the File object from the "os" package
    56  type File interface {
    57  	// for now, the only os.File methods used are those below, add more as necessary
    58  	Name() string
    59  	Write(b []byte) (n int, err error)
    60  	WriteString(s string) (n int, err error)
    61  	Sync() error
    62  	Close() error
    63  	Read(b []byte) (n int, err error)
    64  	Readdir(n int) ([]os.FileInfo, error)
    65  }
    66  

View as plain text