...

Source file src/k8s.io/kubernetes/pkg/util/filesystem/filesystem.go

Documentation: k8s.io/kubernetes/pkg/util/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  package filesystem
    18  
    19  import (
    20  	"os"
    21  	"path/filepath"
    22  	"time"
    23  )
    24  
    25  // Filesystem is an interface that we can use to mock various filesystem operations
    26  type Filesystem interface {
    27  	// from "os"
    28  	Stat(name string) (os.FileInfo, error)
    29  	Create(name string) (File, error)
    30  	Rename(oldpath, newpath string) error
    31  	MkdirAll(path string, perm os.FileMode) error
    32  	Chtimes(name string, atime time.Time, mtime time.Time) error
    33  	RemoveAll(path string) error
    34  	Remove(name string) error
    35  
    36  	// from "os"
    37  	ReadFile(filename string) ([]byte, error)
    38  	TempDir(dir, prefix string) (string, error)
    39  	TempFile(dir, prefix string) (File, error)
    40  	ReadDir(dirname string) ([]os.DirEntry, error)
    41  	Walk(root string, walkFn filepath.WalkFunc) error
    42  }
    43  
    44  // File is an interface that we can use to mock various filesystem operations typically
    45  // accessed through the File object from the "os" package
    46  type File interface {
    47  	// for now, the only os.File methods used are those below, add more as necessary
    48  	Name() string
    49  	Write(b []byte) (n int, err error)
    50  	Sync() error
    51  	Close() error
    52  }
    53  

View as plain text