Skip to content

Commit

Permalink
test: improve test coverage (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Sep 9, 2024
1 parent ff4bff2 commit 444e008
Show file tree
Hide file tree
Showing 29 changed files with 113 additions and 194 deletions.
45 changes: 39 additions & 6 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,56 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install goveralls
run: go install github.com/mattn/goveralls@latest

- name: Install ginkgo
run: go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.0

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Print current directory and workspace
run: |
echo "Current directory: $(pwd)"
echo "GitHub workspace: ${{ github.workspace }}"
- name: Ensure coverage directory exists
run: mkdir -p ${{ github.workspace }}/coverage

- name: Run coverage with ginkgo
working-directory: ${{ github.workspace }}
run: |
ginkgo ./... --json-report ./ginkgo.report -coverpkg=./... \
-coverprofile=./coverage/coverage.out -r
- run: go test -v -coverprofile=coverage.out ./...
- name: Check coverage directory contents
run: ls -la ${{ github.workspace }}/coverage

- uses: shogo82148/actions-goveralls@v1
- name: Run go cover tool
working-directory: ${{ github.workspace }}
run: |
if [ -f "./coverage/coverage.out" ]; then
go tool cover -o ./coverage/coverage.html -html=./coverage/coverage.out
else
echo "coverage.out file not found"
exit 1
fi
- name: Recheck coverage directory
run: ls -la ${{ github.workspace }}/coverage

- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
path-to-profile: ${{ github.workspace }}/coverage/coverage.out

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.out -service=github
run: goveralls -coverprofile=${{ github.workspace }}/coverage/coverage.out -service=github

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
coverage
coverage.out
ginkgo.report
report.json

.task/

Expand Down
13 changes: 9 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ tasks:
cmds:
- go test ./internal/feat/hiber

tf-samp:
cmds:
- go test ./internal/feat/sampling

toc:
cmds:
- go test ./collections
Expand Down Expand Up @@ -200,16 +204,17 @@ tasks:
- mkdir -p ./nfs/coverage
- mkdir -p ./pref/coverage
- mkdir -p ./tapable/coverage
- ginkgo --json-report
- ginkgo ./... --json-report
./ginkgo.report
-coverpkg=./...
-coverprofile=./coverage/coverage.out -r
# ginkgo ./... --json-report=report.json
- go tool cover -html=./coverage/coverage.out -o ./coverage/coverage.html
- open ./coverage/coverage.html

view-cover:
cmds:
- open ./coverage/coverage.html
view-cover:
cmds:
- open ./coverage/coverage.html

# === i18n =================================================

Expand Down
7 changes: 3 additions & 4 deletions builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if optionsErr != nil {
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(optionsErr),
kc: kernel.HadesNav(o, optionsErr),
ext: ext,
}, optionsErr
}

// BUILD NAVIGATOR
//

artefacts, navErr := bs.navigator.Build(o, &types.Resources{
FS: FileSystems{
N: ext.navFS(),
Expand All @@ -61,7 +60,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if navErr != nil {
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(navErr),
kc: kernel.HadesNav(o, navErr),
ext: ext,
}, navErr
}
Expand All @@ -78,7 +77,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if pluginsErr != nil {
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(pluginsErr),
kc: kernel.HadesNav(o, pluginsErr),
ext: ext,
}, pluginsErr
}
Expand Down
20 changes: 20 additions & 0 deletions collections/positional-set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,24 @@ var _ = Describe("PositionalSet", func() {
})
})
})

Context("Contains", func() {
When("item is present", func() {
It("🧪 should: return true", func() {
set.All(rainbow...)
Expect(set.Contains("richard")).To(BeTrue(),
lab.Reason("richard IS contained in set"),
)
})
})

When("item is NOT present", func() {
It("🧪 should: return false", func() {
set.All(rainbow...)
Expect(set.Contains("james")).To(BeFalse(),
lab.Reason("james is NOT contained in set"),
)
})
})
})
})
6 changes: 0 additions & 6 deletions core/navigator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@ import (
type Navigator interface {
Navigate(ctx context.Context) (TraverseResult, error)
}

type Navigate func() (TraverseResult, error)

func (fn Navigate) Navigate() (TraverseResult, error) {
return fn()
}
12 changes: 0 additions & 12 deletions core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,11 @@ func Root(root string, info fs.FileInfo) *Node {
return node
}

// Clone makes shallow copy of Node (excluding the error).
func (n *Node) Clone() *Node {
c := *n
c.Error = nil

return &c
}

// IsFolder indicates wether this node is a folder.
func (n *Node) IsFolder() bool {
return n.dir
}

func (n *Node) key() string {
return n.Extension.SubPath
}

func isDir(n *Node) bool {
if n.Entry != nil {
return n.Entry.IsDir()
Expand Down
8 changes: 0 additions & 8 deletions cycle/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,3 @@ func broadcastHibernate(listeners []HibernateHandler) HibernateHandler {
}

func nopHibernate(_ string) {}

func broadcastSimple(listeners []SimpleHandler) SimpleHandler {
return func() {
for _, listener := range listeners {
listener()
}
}
}
2 changes: 2 additions & 0 deletions director-prime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var _ = Describe("Director(Prime)", Ordered, func() {
Handler: noOpHandler,
},
tv.WithOnAscend(func(_ *core.Node) {}),
tv.WithNoRecurse(),
)).Navigate(ctx)

Expect(err).To(Succeed())
Expand Down Expand Up @@ -105,6 +106,7 @@ var _ = Describe("Director(Prime)", Ordered, func() {
Handler: noOpHandler,
},
tv.WithOnBegin(func(_ *cycle.BeginState) {}),
tv.WithCPU(),
)).Navigate(ctx)

wg.Wait()
Expand Down
24 changes: 0 additions & 24 deletions enums/directory-contents-en-auto.go

This file was deleted.

17 changes: 0 additions & 17 deletions enums/directory-contents-en.go

This file was deleted.

2 changes: 1 addition & 1 deletion extent.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (ex *resumeExtent) options(settings ...pref.Option) (*pref.Options, error)
loaded, err := resume.Load(ex.fileSys.res, ex.w.From, settings...)
ex.loaded = loaded

// get the resume point from the resume persistence file
// TODO: get the resume point from the resume persistence file
// then set up hibernation with this defined as a hibernation
// filter.
//
Expand Down
4 changes: 0 additions & 4 deletions internal/feat/filter/filter-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ type plugin struct {
scheme scheme
}

func (p *plugin) Name() string {
return "filtering"
}

func (p *plugin) Register(kc types.KernelController) error {
if err := p.BasePlugin.Register(kc); err != nil {
return err
Expand Down
7 changes: 0 additions & 7 deletions internal/feat/filter/scheme-custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/snivilised/traverse/internal/measure"
"github.com/snivilised/traverse/internal/third/lo"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/pref"
)

type customScheme struct {
Expand All @@ -17,12 +16,6 @@ type customScheme struct {
func (s *customScheme) create() error {
s.filter = s.o.Filter.Custom

if s.o.Filter.Sink != nil {
s.o.Filter.Sink(pref.FilterReply{
Node: s.filter,
})
}

return s.filter.Validate()
}

Expand Down
10 changes: 2 additions & 8 deletions internal/feat/filter/scheme-sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/snivilised/traverse/internal/third/lo"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/nfs"
"github.com/snivilised/traverse/pref"
)

type samplerScheme struct {
Expand All @@ -33,13 +32,8 @@ func (s *samplerScheme) create() error {
_ fs.ReadDirFS, _ string,
) ([]fs.DirEntry, error) {
return s.filter.Matching(result), err
})

if s.o.Filter.Sink != nil {
s.o.Filter.Sink(pref.FilterReply{
Sampler: s.filter,
})
}
},
)

return filter.Validate()
}
Expand Down
4 changes: 0 additions & 4 deletions internal/feat/hiber/hibernate-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ type plugin struct {
profile profile
}

func (p *plugin) Name() string {
return "hibernation"
}

func (p *plugin) Next(node *core.Node, inspection types.Inspection) (bool, error) {
return p.profile.next(node, inspection)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/feat/hiber/hibernate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ var _ = Describe("feature", Ordered, func() {
},
),

// This is only required to change the default inclusivity
// of the wake condition; by default is inclusive.
tv.WithHibernationBehaviourExclusiveWake(),

// This is only required to change the default inclusivity
// of the sleep condition; by default is exclusive.
tv.WithHibernationBehaviourInclusiveSleep(),

tv.WithHookQueryStatus(
func(qsys fs.StatFS, path string) (fs.FileInfo, error) {
return qsys.Stat(lab.TrimRoot(path))
Expand Down
4 changes: 0 additions & 4 deletions internal/feat/nanny/nanny-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ type plugin struct {
crate measure.Crate
}

func (p *plugin) Name() string {
return "nanny"
}

func (p *plugin) Next(node *core.Node,
inspection types.Inspection,
) (bool, error) {
Expand Down
4 changes: 0 additions & 4 deletions internal/feat/resume/resume-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type Plugin struct {
IfResult core.ResultCompletion
}

func (p *Plugin) Name() string {
return "resume"
}

func (p *Plugin) Next(node *core.Node, inspection types.Inspection) (bool, error) {
_, _ = node, inspection
// apply the wake filter
Expand Down
1 change: 1 addition & 0 deletions internal/feat/sampling/navigator-sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var _ = Describe("feature", Ordered, func() {
Folders: 2,
},
}),

tv.WithHookQueryStatus(
func(qsys fs.StatFS, path string) (fs.FileInfo, error) {
return qsys.Stat(lab.TrimRoot(path))
Expand Down
4 changes: 0 additions & 4 deletions internal/feat/sampling/sampling-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ type plugin struct {
ctrl controller
}

func (p *plugin) Name() string {
return "sampling"
}

func (p *plugin) Init(_ *types.PluginInit) error {
p.O.Hooks.ReadDirectory.Chain(
p.ctrl.sample,
Expand Down
Loading

0 comments on commit 444e008

Please sign in to comment.