forked from wimspaargaren/prolayout
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.task | ||
.vscode | ||
coverage.html | ||
functioncoverage.out | ||
profile.cov | ||
reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,8 @@ linters: | |
- nilnil | ||
- nlreturn | ||
- paralleltest | ||
- revive | ||
- testpackage | ||
- varnamelen | ||
- wsl | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
module: "github.com/wimspaargaren/prolayout" | ||
root: | ||
- name: "bar" | ||
- name: "internal" | ||
- name: "tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package analyzer | ||
|
||
import ( | ||
"go/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/wimspaargaren/prolayout/internal/model" | ||
) | ||
|
||
func TestAssessDir(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
pass *analysis.Pass | ||
expected *model.Dir | ||
hasError bool | ||
}{ | ||
{ | ||
name: "if folder contains a '.test' suffix, then skip assessDir and return nil twice", | ||
pass: &analysis.Pass{ | ||
Pkg: types.NewPackage("github.com/wimspaargaren/prolayout/tests.test", "main"), | ||
}, | ||
expected: nil, | ||
hasError: false, | ||
}, | ||
{ | ||
name: "if folder contains a '.something' suffix, then loop through and return 'dir *model.Dir' at the end", | ||
pass: &analysis.Pass{ | ||
Pkg: types.NewPackage("github.com/wimspaargaren/prolayout/tests.something", "main"), | ||
}, | ||
expected: &model.Dir{Name: "", Files: []*model.File(nil), Dirs: []*model.Dir(nil)}, | ||
hasError: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
r := &runner{Root: model.Root{Root: []*model.Dir{{Name: "internal"}}}} | ||
dir, err := r.assessDir(tc.pass) | ||
if tc.hasError { | ||
assert.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
assert.Equal(t, tc.expected, dir) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/wimspaargaren/prolayout/internal/model" | ||
) | ||
|
||
func TestReadAndUnmarshalProLayoutYML(t *testing.T) { | ||
exp := model.Root{ | ||
Module: "github.com/wimspaargaren/prolayout", | ||
Root: []*model.Dir{{Name: "bar"}, {Name: "internal"}, {Name: "tests"}}, | ||
} | ||
act, err := readAndUnmarshalProLayoutYML(proLayoutFile) | ||
require.NoError(t, err) | ||
assert.Equal(t, exp, *act) | ||
|
||
act, err = readAndUnmarshalProLayoutYML(proLayoutFile + "-does-not-exist") | ||
require.Empty(t, act) | ||
assert.EqualError(t, err, "'open .prolayout.yml-does-not-exist: no such file or directory'") | ||
} |