Skip to content

Commit

Permalink
test(tui): add view tests (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Broderick-Westrope authored Dec 26, 2024
1 parent bd944b2 commit a08a8e4
Show file tree
Hide file tree
Showing 34 changed files with 1,684 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.golden -text
12 changes: 4 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ linters-settings:
nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [ funlen, gocognit, lll ]
allow-no-explanation: [funlen, gocognit, lll]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
Expand Down Expand Up @@ -179,12 +179,9 @@ linters-settings:
# Default: false
all: true


linters:
disable-all: true
enable:
# TODO: enable the following over time
# - testpackage # makes you use a separate _test package
## enabled by default
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
Expand Down Expand Up @@ -297,7 +294,6 @@ linters:
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines


issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
Expand All @@ -306,9 +302,9 @@ issues:

exclude-rules:
- source: "(noinspection|TODO)"
linters: [ godot ]
linters: [godot]
- source: "//noinspection"
linters: [ gocritic ]
linters: [gocritic]
- path: "_test\\.go"
linters:
- bodyclose
Expand All @@ -317,4 +313,4 @@ issues:
- goconst
- gosec
- noctx
- wrapcheck
- wrapcheck
9 changes: 9 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with-expecter: true
inpackage: true
dir: "{{.InterfaceDir}}"
outpkg: "{{.PackageName}}"

packages:
github.com/Broderick-Westrope/tetrigo/internal/tui/components:
interfaces:
Stopwatch: {}
20 changes: 13 additions & 7 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
version: '3'
version: "3"

env:
GOLANG_CROSS_VERSION: 'v1.22'
PACKAGE_NAME: 'github.com/Broderick-Westrope/tetrigo'
GOLANG_CROSS_VERSION: "v1.22"
PACKAGE_NAME: "github.com/Broderick-Westrope/tetrigo"

tasks:
default:
cmds:
- task: codegen
- task: lint
- task: test

install:
desc: Installs Tetrigo
aliases: [i]
sources:
- './**/*.go'
- "./**/*.go"
cmds:
- go install -v ./cmd/tetrigo

Expand All @@ -24,19 +25,24 @@ tasks:
- go mod download
- go mod tidy

codegen:
desc: Generate code dependencies
cmds:
- mockery

lint:
desc: Runs golangci-lint
aliases: [l]
sources:
- './**/*.go'
- "./**/*.go"
- .golangci.yaml
cmds:
- golangci-lint run

lint:fix:
desc: Runs golangci-lint and fixes any issues
sources:
- './**/*.go'
- "./**/*.go"
- .golangci.yaml
cmds:
- golangci-lint run --fix
Expand Down Expand Up @@ -76,4 +82,4 @@ tasks:
goreleaser:release:
desc: Releases the project
cmds:
- bash ./scripts/goreleaser/release.sh
- bash ./scripts/goreleaser/release.sh
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.3

require (
github.com/Broderick-Westrope/charmutils v0.0.0-20241115050827-f328b6667400
github.com/Broderick-Westrope/x/exp/teatest v0.0.0-20241225091642-1c6e3bb330ba
github.com/BurntSushi/toml v1.4.0
github.com/adrg/xdg v0.5.3
github.com/alecthomas/kong v1.4.0
Expand All @@ -18,13 +19,17 @@ require (
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.4.5 // indirect
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20241113152101-0af7d04e9f32 // indirect
github.com/charmbracelet/x/exp/teatest v0.0.0-20241222104055-e1130b311607 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
Expand All @@ -35,8 +40,11 @@ require (
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 23 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/Broderick-Westrope/charmutils v0.0.0-20241115050827-f328b6667400 h1:cb9Y/X/7+JemuYjw/Fv2ELVgtd6BwIiB82EMbmm7wGs=
github.com/Broderick-Westrope/charmutils v0.0.0-20241115050827-f328b6667400/go.mod h1:oh2FSHkUk/5karkxreTzft6smriW821P7puhvnrOMtw=
github.com/Broderick-Westrope/x/exp/teatest v0.0.0-20241225091642-1c6e3bb330ba h1:NtGVUvXNWt25u4tbNwZxkCZOsImEJ+x82eNXWdZTba8=
github.com/Broderick-Westrope/x/exp/teatest v0.0.0-20241225091642-1c6e3bb330ba/go.mod h1:M39MtESS/g+wP2Njvdjgj5rykE7Di1Ms/7ItsJ8A3+g=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
Expand Down Expand Up @@ -34,8 +36,11 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAM
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/strings v0.0.0-20241113152101-0af7d04e9f32 h1:YGyLdtHqkyqlKe1bPsDfI+5Dl1SToZ97+F2Nv34GKAY=
github.com/charmbracelet/x/exp/strings v0.0.0-20241113152101-0af7d04e9f32/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
github.com/charmbracelet/x/exp/teatest v0.0.0-20241222104055-e1130b311607 h1:nKQq4Yrr4WxsM5SDXahuEByNH2ncW6at+LV3uH4wzEk=
github.com/charmbracelet/x/exp/teatest v0.0.0-20241222104055-e1130b311607/go.mod h1:ag+SpTUkiN/UuUGYPX3Ci4fR1oF3XX97PpGhiXK7i6U=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand All @@ -44,6 +49,14 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand All @@ -62,11 +75,17 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
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/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
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=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
Expand All @@ -77,7 +96,10 @@ golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func GetConfig(path string) (*Config, error) {
MaxLevel: 15,
EndOnMaxLevel: false,

Theme: defaultTheme(),
Keys: defaultKeys(),
Theme: DefaultTheme(),
Keys: DefaultKeys(),
}

_, err := toml.DecodeFile(path, &c)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Keys struct {
RotateClockwise []string `toml:"rotate_clockwise"`
}

func defaultKeys() *Keys {
func DefaultKeys() *Keys {
return &Keys{
ForceQuit: []string{"ctrl+c"},
Exit: []string{"esc"},
Expand Down
2 changes: 1 addition & 1 deletion internal/config/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Theme struct {
} `toml:"characters"`
}

func defaultTheme() *Theme {
func DefaultTheme() *Theme {
theme := new(Theme)

theme.Colours.TetriminoCells.I = "#64C4EB"
Expand Down
4 changes: 2 additions & 2 deletions internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ func NewDB(dataSourceName string) (*sql.DB, error) {
return nil, err
}

err = ensureTablesExist(db)
err = EnsureTablesExist(db)
if err != nil {
return nil, err
}

return db, nil
}

func ensureTablesExist(db *sql.DB) error {
func EnsureTablesExist(db *sql.DB) error {
// Leaderboard table
_, err := db.Exec(
`CREATE TABLE IF NOT EXISTS leaderboard
Expand Down
Loading

0 comments on commit a08a8e4

Please sign in to comment.