Skip to content

Commit

Permalink
mvp done
Browse files Browse the repository at this point in the history
  • Loading branch information
myxo authored Apr 30, 2024
1 parent 6d44046 commit 09ff383
Show file tree
Hide file tree
Showing 10 changed files with 386 additions and 219 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v -rapid.checks=50000 ./...
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ Features:
- profound testing (we use property based tsting to ensure simularity with real implementation

Non features:
- make a varaity of different backends (like NetFS, s2, etc.). I try to keep package as clean from dependencies as possible
- make a varaity of different backends (like NetFS, google cloud, s3, etc.). I try to keep package as clean from dependencies as possible
- simulating of concurrent effect of filesystem (e.g. concurrent ReadDir with file removing)

TODO:
- [ ] Make count in test to see how much function envocation we have
- [ ] Document what fileMode are supported
- [ ] O_APPEND
- [ ] Fallocate?
- [ ] copy paste docs from orig functions
- [ ] subdirs in tests
- [ ] CI with test and fmtcheck
- [ ] Use more stdlib errors (how to test this?)
- [ ] Test relative paths
- [ ] Test wrapped error?
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/myxo/gofs

go 1.22.0
go 1.21

require (
github.com/stretchr/testify v1.9.0
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
57 changes: 37 additions & 20 deletions gofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ type FS interface {
Rename(oldpath, newpath string) error
Truncate(name string, size int64) error
WriteFile(name string, data []byte, perm os.FileMode) error
Stat(name string) (os.FileInfo, error)
}

type File struct {
mockFile *FakeFile
osFile *os.File
}

var _ io.ReadCloser = &File{}
var _ io.WriteCloser = &File{}
var _ io.ReaderAt = &File{}

func NewFromOs(fp *os.File) *File {
return &File{osFile: fp}
}
Expand Down Expand Up @@ -165,86 +170,98 @@ func (f *File) WriteString(s string) (n int, err error) {
}
func (f *File) WriteTo(w io.Writer) (n int64, err error) { panic("todo") }

func (f *File) IsFake() bool {
return f.osFile == nil
}

//func (f *File) SetDeadline(t time.Time) error{ panic("todo") }
//func (f *File) SetReadDeadline(t time.Time) error{ panic("todo") }
//func (f *File) SetWriteDeadline(t time.Time) error{ panic("todo") }

type OsFs struct{}
type osFs struct{}

var _ FS = &OsFs{}
var _ FS = &osFs{}

func (OsFs) Create(name string) (*File, error) {
func OsFs() FS {
return &osFs{}
}

func (osFs) Create(name string) (*File, error) {
fp, err := os.Create(name)
return NewFromOs(fp), err
}

func (OsFs) CreateTemp(dir, pattern string) (*File, error) {
func (osFs) CreateTemp(dir, pattern string) (*File, error) {
fp, err := os.CreateTemp(dir, pattern)
return NewFromOs(fp), err
}

func (OsFs) Open(name string) (*File, error) {
func (osFs) Open(name string) (*File, error) {
fp, err := os.Open(name)
return NewFromOs(fp), err
}

func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (*File, error) {
func (osFs) OpenFile(name string, flag int, perm os.FileMode) (*File, error) {
fp, err := os.OpenFile(name, flag, perm)
return NewFromOs(fp), err
}

func (OsFs) Chdir(dir string) error {
func (osFs) Chdir(dir string) error {
return os.Chdir(dir)
}

func (OsFs) Chmod(name string, mode os.FileMode) error {
func (osFs) Chmod(name string, mode os.FileMode) error {
return os.Chmod(name, mode)
}

func (OsFs) Chown(name string, uid, gid int) error {
func (osFs) Chown(name string, uid, gid int) error {
return os.Chown(name, uid, gid)
}

func (OsFs) Mkdir(name string, perm os.FileMode) error {
func (osFs) Mkdir(name string, perm os.FileMode) error {
return os.Mkdir(name, perm)
}

func (OsFs) MkdirAll(path string, perm os.FileMode) error {
func (osFs) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}

func (OsFs) MkdirTemp(dir, pattern string) (string, error) {
func (osFs) MkdirTemp(dir, pattern string) (string, error) {
return os.MkdirTemp(dir, pattern)
}

func (OsFs) ReadFile(name string) ([]byte, error) {
func (osFs) ReadFile(name string) ([]byte, error) {
return os.ReadFile(name)
}

func (OsFs) Readlink(name string) (string, error) {
func (osFs) Readlink(name string) (string, error) {
return os.Readlink(name)
}

func (OsFs) Remove(name string) error {
func (osFs) Remove(name string) error {
return os.Remove(name)
}

func (OsFs) RemoveAll(path string) error {
func (osFs) RemoveAll(path string) error {
return os.RemoveAll(path)
}

func (OsFs) Rename(oldpath, newpath string) error {
func (osFs) Rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath)
}

func (OsFs) Truncate(name string, size int64) error {
func (osFs) Truncate(name string, size int64) error {
return os.Truncate(name, size)
}

func (OsFs) WriteFile(name string, data []byte, perm os.FileMode) error {
func (osFs) WriteFile(name string, data []byte, perm os.FileMode) error {
return os.WriteFile(name, data, perm)
}

func (OsFs) ReadDir(name string) ([]os.DirEntry, error) {
func (osFs) ReadDir(name string) ([]os.DirEntry, error) {
return os.ReadDir(name)
}

func (osFs) Stat(name string) (os.FileInfo, error) {
return os.Stat(name)
}
Loading

0 comments on commit 09ff383

Please sign in to comment.