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 10, 2024
1 parent ff4bff2 commit 56064f2
Show file tree
Hide file tree
Showing 29 changed files with 167 additions and 201 deletions.
104 changes: 94 additions & 10 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Traverse Continuous Integration

on:
push:

Expand All @@ -25,25 +26,108 @@ jobs:

runs-on: ${{ matrix.platform }}

# Defining variables is awkward in gh-actions, they can't just be declared
# anywhere; in particular they can't be declared at the top of this file,
# nor can they be declared inside steps.
#
# see: GitHub Actions/Write workflows/Choose what workflows do/
# Store information in variables
#
env:
COVERAGE_OUTPUT: ${{ github.workspace }}/coverage.out

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

- run: go test -v -coverprofile=coverage.out ./...
- name: Print current directory and workspace
run: |
echo "🔹 Current directory: $(pwd) \n"
echo "🔹 GitHub workspace: ${{ github.workspace }} \n"
echo "🔹 COVERAGE_OUTPUT: $COVERAGE_OUTPUT \n"
- uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
- name: Ensure coverage directory exists
run: |
mkdir -p ${{ github.workspace }}/coverage
mkdir -p ${{ github.workspace }}/collections/coverage
mkdir -p ${{ github.workspace }}/core/coverage/
mkdir -p ${{ github.workspace }}/cycle/coverage
mkdir -p ${{ github.workspace }}/enums/coverage
mkdir -p ${{ github.workspace }}/internal/feat/filter/coverage
mkdir -p ${{ github.workspace }}/internal/feat/hiber/coverage
mkdir -p ${{ github.workspace }}/internal/feat/resume/coverage
mkdir -p ${{ github.workspace }}/internal/feat/sampling/coverage
mkdir -p ${{ github.workspace }}/internal/filtering/coverage
mkdir -p ${{ github.workspace }}/internal/kernel/coverage
mkdir -p ${{ github.workspace }}/internal/level/coverage
mkdir -p ${{ github.workspace }}/internal/measure/coverage
mkdir -p ${{ github.workspace }}/internal/services/coverage
mkdir -p ${{ github.workspace }}/internal/level/coverage
mkdir -p ${{ github.workspace }}/internal/third/bus/coverage
mkdir -p ${{ github.workspace }}/internal/third/lo/coverage
mkdir -p ${{ github.workspace }}/internal/types/coverage
mkdir -p ${{ github.workspace }}/locale/coverage
mkdir -p ${{ github.workspace }}/nfs/coverage
mkdir -p ${{ github.workspace }}/pref/coverage
mkdir -p ${{ github.workspace }}/tapable/coverage
# This should be ginko
# This works, but produces bad results (too many incorrect 0% coverage),
# so we need to get ginkgo working.
#
# - name: Run tests and generate coverage profile with Go test
# run: |
# go test ./... -coverprofile=${{ github.workspace }}/coverage/coverage.out

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.out -service=github
# - name: Run tests and generate coverage profile with Ginkgo
# run: ginkgo ./... --json-report ./ginkgo.report \
# -coverpkg=$(go list github.com/snivilised/traverse/...) \
# -coverprofile=${{ github.workspace }}/coverage/coverage.out -r

# onsi:
- name: Run tests and generate coverage profile with Ginkgo
run: ginkgo ./... --json-report ./ginkgo.report \
-coverpkg=$(go list github.com/snivilised/traverse/...) \
-coverprofile=${{ env.COVERAGE_OUTPUT }} -r

- name: list .out files
run:
echo "🔺 listing out files....\n"
ls -la ${{ github.workspace }}/*.out

#######

# - name: Check if coverage file exists
# run: |
# if [ -f "${{ env.COVERAGE_OUTPUT }}" ]; then
# echo "Coverage file generated successfully"
# else
# echo "Coverage file not found"
# exit 1
# fi

- name: Generate HTML coverage report
run: |
if [ -f ${{ env.COVERAGE_OUTPUT }} ]; then
go tool cover -html=${{ env.COVERAGE_OUTPUT }} -o ${{ github.workspace }}/coverage/coverage.html
else
echo "coverage.out file not found"
exit 1
fi
- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: ${{ env.COVERAGE_OUTPUT }}
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
15 changes: 8 additions & 7 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,13 @@ tasks:
- mkdir -p ./nfs/coverage
- mkdir -p ./pref/coverage
- mkdir -p ./tapable/coverage
- ginkgo --json-report
./ginkgo.report
-coverpkg=./...
-coverprofile=./coverage/coverage.out -r
- ginkgo ./... --json-report ./ginkgo.report -coverpkg=$(go list github.com/snivilised/traverse/...) -coverprofile=./coverage/coverage.out -r
- 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
Loading

0 comments on commit 56064f2

Please sign in to comment.