Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andygeiss committed Jun 19, 2021
1 parent bd633fe commit 6ede4c6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions clients/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/andygeiss/method2go/services/project"
"github.com/andygeiss/method2go/services/project/engines"
"github.com/andygeiss/method2go/services/project/resourceaccess"
"github.com/andygeiss/method2go/services/project/resources"
)

var (
Expand Down Expand Up @@ -69,7 +69,7 @@ func main() {
}
ensureDefaults()
name := os.Args[1]
ra := resourceaccess.NewFileSystem(name, files)
ra := resources.NewProjectResourceAccessFileSystem(name, files)
te := engines.NewDefaultTemplateEngine(&content, ".configs", files)
pm := project.NewManager(te, ra)
_ = pm.CreateByName(context.Background(), name)
Expand Down
40 changes: 0 additions & 40 deletions services/project/resourceAccess/utils_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package resourceaccess
package resources

import (
"os"
Expand All @@ -7,13 +7,13 @@ import (
"github.com/andygeiss/method2go/services/project"
)

// FileSystem ...
type FileSystem struct {
// ProjectResourceAccessFileSystem ...
type ProjectResourceAccessFileSystem struct {
files []string
path string
}

func (a *FileSystem) GenerateProjectStructure(p *project.Project) (err error) {
func (a *ProjectResourceAccessFileSystem) GenerateProjectStructure(p *project.Project) (err error) {
for _, file := range a.files {
dst := filepath.Join(a.path, file)
data := []byte(p.Contents[file])
Expand All @@ -27,9 +27,9 @@ func (a *FileSystem) GenerateProjectStructure(p *project.Project) (err error) {
return nil
}

// NewFileSystem ...
func NewFileSystem(path string, files []string) project.ProjectResourceAccess {
return &FileSystem{
// NewProjectResourceAccessFileSystem ...
func NewProjectResourceAccessFileSystem(path string, files []string) project.ProjectResourceAccess {
return &ProjectResourceAccessFileSystem{
files: files,
path: path,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package resourceaccess_test
package resources_test

import (
"os"
"path/filepath"
"testing"

"github.com/andygeiss/method2go/services/project"
"github.com/andygeiss/method2go/services/project/resourceaccess"
"github.com/andygeiss/method2go/services/project/resources"
assert "github.com/andygeiss/utilities/testing"
)

func TestFileSystem_GenerateProjectStructure_Should_Return_Without_An_Error(t *testing.T) {
os.RemoveAll("testdata")
repository := resourceaccess.NewFileSystem("testdata", []string{"foo/bar/foo.txt"})
access := resources.NewProjectResourceAccessFileSystem("testdata", []string{"foo/bar/foo.txt"})
project := &project.Project{
Contents: map[string]string{
"foo/bar/foo.txt": "bar",
},
}
err := repository.GenerateProjectStructure(project)
exists := resourceaccess.HasFile(filepath.Join("testdata", "foo", "bar", "foo.txt"))
err := access.GenerateProjectStructure(project)
exists := resources.HasFile(filepath.Join("testdata", "foo", "bar", "foo.txt"))
assert.That("error should be nil", t, err, nil)
assert.That("project should not be nil", t, project == nil, false)
assert.That("foo/bar/main.go should exists", t, exists, true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package resourceaccess
package resources

import (
"os"
Expand Down
40 changes: 40 additions & 0 deletions services/project/resources/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package resources_test

import (
"os"
"path/filepath"
"testing"

"github.com/andygeiss/method2go/services/project/resources"
assert "github.com/andygeiss/utilities/testing"
)

func TestCreateFolders_Should_Create_One_Folder(t *testing.T) {
os.RemoveAll("foo")
err := resources.CreateFolders("foo")
assert.That("err should be nil", t, err, nil)
assert.That("project folder exists", t, resources.HasFolder("foo"), true)
}

func TestCreateFolders_Should_Create_Two_Folders(t *testing.T) {
err := resources.CreateFolders("foo", filepath.Join("foo", "bar"))
assert.That("err should be nil", t, err, nil)
assert.That("folder [foo] exists", t, resources.HasFolder("foo"), true)
assert.That("folder [foo/bar] exists", t, resources.HasFolder(filepath.Join("foo", "bar")), true)
os.RemoveAll("foo")
}

func TestCreateFoldersByFile_Should_Create_One_Folder(t *testing.T) {
err := resources.CreateFoldersByFile(filepath.Join("foo", "bar.go"))
assert.That("err should be nil", t, err, nil)
assert.That("folder [foo] exists", t, resources.HasFolder("foo"), true)
os.RemoveAll("foo")
}

func TestCreateFoldersByFile_Should_Create_Two_Folders(t *testing.T) {
err := resources.CreateFoldersByFile(filepath.Join("foo", "bar.go"))
assert.That("err should be nil", t, err, nil)
assert.That("folder [foo] exists", t, resources.HasFolder("foo"), true)
assert.That("folder [foo/bar] does not exists", t, resources.HasFolder(filepath.Join("foo", "bar.go")), false)
os.RemoveAll("foo")
}

0 comments on commit 6ede4c6

Please sign in to comment.