Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

buffalo test -m Test commands fail when using sqlite3 databases #180

Closed
mattbnz opened this issue Jun 30, 2022 · 3 comments · Fixed by #181
Closed

buffalo test -m Test commands fail when using sqlite3 databases #180

mattbnz opened this issue Jun 30, 2022 · 3 comments · Fixed by #181
Assignees
Labels
bug Something isn't working

Comments

@mattbnz
Copy link

mattbnz commented Jun 30, 2022

Description

Attempting to run an individual test case against a project using an sqlite3 database fails because of what I think is buggy path handling logic in the meta package... but I'm not entirely sure if it's intended to be able to call that package from a subdirectory of the app.... so filing this here at the top-level...

When using test -m, mFlagRunner changes into the module directory before calling newTestCmd, which calls into meta.New to try and find the app config. Unfortunately when called from with a module directory (not the base app directory) the path handling logic in meta.New generates a bad path for buffalo-config.toml and fails to find it, falling back instead ot the "oldSchool" method which also looks in the wrong place for .buffalo.dev.yaml - with neither of them finding a config file, the build tags are not found, and therefore not passed along to the go test invocation, and the test methods subsequently run without sqlite support :(

I don't know if it's important for the test command to change the working directory before calling newTestCmd? if not, re-ordering that would be an easy fix... although probably the logic in the meta package needs to be made more robust about working regardless of where it's called from.

Separately, along the way I noticed that the sqlite build tag never makes its way into the 'oldSchool' config file, so even if that fallback path was found with the new config wasn't, there's a missing link.... not sure if this is still important to anything else, but may be a contributor to issues like gobuffalo/buffalo#465 even for brand new projects.

Finally, I realise this is an issue in the stable release, and may be fixed in the development branches... but they're so different and divergent in their codebases, that I struggled to find out, and its' significant enough that I think it warrants a fix in the stable branch anyway, hence this bug.

Cheers

Steps to Reproduce the Problem

  1. buffalo new testapp --db-type sqlite3
  2. buffalo pop g model Test
  3. buffalo test -m Test_Test

Expected Behavior

The test will fail anyway, as it's unimplemented, but in the console output you should see go test being called with -tags sqlite, and there should not be any errors from pop.

Actual Behavior

matt@argon:~/src/buffalo/test2$ buffalo test -m Test_Test
INFO[0000] no test database to drop                     
[POP] 2022/07/01 01:39:29 info - created database '/home/matt/src/buffalo/test2_test2_test.sqlite'
[POP] 2022/07/01 01:39:29 info - > create_tests
[POP] 2022/07/01 01:39:29 info - Successfully applied 1 migrations.
[POP] 2022/07/01 01:39:29 info - 0.0157 seconds
[POP] 2022/07/01 01:39:29 info - dumped schema for /home/matt/src/buffalo/test2_test2_test.sqlite
INFO[0001] go test -p 1 -tags development -run Test_Test 
[POP] 2022/07/01 01:39:31 warn - unable to load connection development: could not create new connection: sqlite3 support was not compiled into the binary
[POP] 2022/07/01 01:39:31 warn - unable to load connection test: could not create new connection: sqlite3 support was not compiled into the binary
[POP] 2022/07/01 01:39:31 warn - unable to load connection production: could not create new connection: sqlite3 support was not compiled into the binary
2022/07/01 01:39:31 could not find connection named test

Info

matt@argon:~/src/buffalo/test2$  buffalo info
-> Go: Checking installation
✓ The `go` executable was found on your system at: /usr/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.18.1, meets the minimum requirements.

-> Go: Checking Package Management
✓ You are using Go Modules (`go`) for package management.

-> Go: Checking PATH
✓ Your PATH contains /home/matt/go/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /usr/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v12.22.9, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /usr/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 8.5.1, meets the minimum requirements.

-> Yarn: Checking installation
✓ The `yarnpkg` executable was found on your system at: /home/matt/.npm-global/bin/yarnpkg

-> Yarn: Checking minimum version requirements
✓ Your version of Yarn, 3.2.1, meets the minimum requirements.

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✘ The `mysql` executable could not be found on your system.
For help setting up your MySQL environment please follow the instructions for you platform at:

https://www.mysql.com/downloads/

-> SQLite3: Checking installation
✓ The `sqlite3` executable was found on your system at: /usr/bin/sqlite3

-> SQLite3: Checking minimum version requirements
✓ Your version of SQLite3, 3.37.2, meets the minimum requirements.

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo (CLI): Checking installation
✓ The `buffalo` executable was found on your system at: /home/matt/go/bin/buffalo

-> Buffalo (CLI): Checking minimum version requirements
✓ Your version of Buffalo (CLI), v0.18.6, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /home/matt/src/buffalo/test2
Root        /home/matt/src/buffalo/test2
GoPath      /home/matt/go
PackagePkg  test2
ActionsPkg  test2/actions
ModelsPkg   test2/models
GriftsPkg   test2/grifts
WithModules true
Name        test2
Bin         bin/test2
VCS         git
WithPop     true
WithSQLite  true
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    true
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[build:webpack --mode production --progress dev:webpack --watch]}

-> Buffalo: config/buffalo-app.toml
name = "test2"
bin = "bin/test2"
vcs = "git"
with_pop = true
with_sqlite = true
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop/v3@latest"
  tags = ["sqlite"]

-> Buffalo: go.mod
module test2

go 1.18

require (
	github.com/gobuffalo/buffalo v0.18.7
	github.com/gobuffalo/buffalo-pop/v3 v3.0.4
	github.com/gobuffalo/envy v1.10.1
	github.com/gobuffalo/mw-csrf v1.0.0
	github.com/gobuffalo/mw-forcessl v0.0.0-20220514125302-be60179938a4
	github.com/gobuffalo/mw-i18n/v2 v2.0.1
	github.com/gobuffalo/mw-paramlogger v1.0.0
	github.com/gobuffalo/pop/v6 v6.0.4
	github.com/gobuffalo/suite/v4 v4.0.2
	github.com/gobuffalo/validate/v3 v3.3.1
	github.com/gofrs/uuid v4.2.0+incompatible
	github.com/markbates/grift v1.5.0
	github.com/unrolled/secure v1.10.0
)

require (
	github.com/BurntSushi/toml v1.1.0 // indirect
	github.com/Masterminds/semver/v3 v3.1.1 // indirect
	github.com/aymerick/douceur v0.2.0 // indirect
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/dustin/go-humanize v1.0.0 // indirect
	github.com/fatih/color v1.13.0 // indirect
	github.com/fatih/structs v1.1.0 // indirect
	github.com/felixge/httpsnoop v1.0.1 // indirect
	github.com/fsnotify/fsnotify v1.5.1 // indirect
	github.com/go-sql-driver/mysql v1.6.0 // indirect
	github.com/gobuffalo/events v1.4.2 // indirect
	github.com/gobuffalo/fizz v1.14.0 // indirect
	github.com/gobuffalo/flect v0.2.5 // indirect
	github.com/gobuffalo/github_flavored_markdown v1.1.1 // indirect
	github.com/gobuffalo/helpers v0.6.4 // indirect
	github.com/gobuffalo/httptest v1.5.1 // indirect
	github.com/gobuffalo/logger v1.0.6 // indirect
	github.com/gobuffalo/meta v0.3.1 // indirect
	github.com/gobuffalo/nulls v0.4.1 // indirect
	github.com/gobuffalo/plush/v4 v4.1.11 // indirect
	github.com/gobuffalo/tags/v3 v3.1.2 // indirect
	github.com/gorilla/css v1.0.0 // indirect
	github.com/gorilla/handlers v1.5.1 // indirect
	github.com/gorilla/mux v1.8.0 // indirect
	github.com/gorilla/securecookie v1.1.1 // indirect
	github.com/gorilla/sessions v1.2.1 // indirect
	github.com/inconshreveable/mousetrap v1.0.0 // indirect
	github.com/jackc/chunkreader/v2 v2.0.1 // indirect
	github.com/jackc/pgconn v1.12.1 // indirect
	github.com/jackc/pgio v1.0.0 // indirect
	github.com/jackc/pgpassfile v1.0.0 // indirect
	github.com/jackc/pgproto3/v2 v2.3.0 // indirect
	github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
	github.com/jackc/pgtype v1.11.0 // indirect
	github.com/jackc/pgx/v4 v4.16.1 // indirect
	github.com/jmoiron/sqlx v1.3.5 // indirect
	github.com/joho/godotenv v1.4.0 // indirect
	github.com/karrick/godirwalk v1.16.1 // indirect
	github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
	github.com/luna-duclos/instrumentedsql v1.1.3 // indirect
	github.com/markbates/oncer v1.0.0 // indirect
	github.com/markbates/refresh v1.12.0 // indirect
	github.com/markbates/safe v1.0.1 // indirect
	github.com/mattn/go-colorable v0.1.12 // indirect
	github.com/mattn/go-isatty v0.0.14 // indirect
	github.com/mattn/go-sqlite3 v1.14.9 // indirect
	github.com/microcosm-cc/bluemonday v1.0.16 // indirect
	github.com/mitchellh/go-homedir v1.1.0 // indirect
	github.com/monoculum/formam v3.5.5+incompatible // indirect
	github.com/nicksnyder/go-i18n v1.10.1 // indirect
	github.com/pelletier/go-toml v1.9.3 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	github.com/rogpeppe/go-internal v1.8.0 // indirect
	github.com/sergi/go-diff v1.2.0 // indirect
	github.com/sirupsen/logrus v1.8.1 // indirect
	github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
	github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
	github.com/spf13/cobra v1.4.0 // indirect
	github.com/spf13/pflag v1.0.5 // indirect
	github.com/stretchr/testify v1.7.1 // indirect
	golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
	golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
	golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
	golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
	golang.org/x/text v0.3.7 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
mattbnz referenced this issue in mattbnz/meta Jun 30, 2022
When called from within a subdirectory of the app (e.g. from within the
processing of buffalo test -m TestName) we need to strip an extra
directory off to be able to find the configs, etc.

Failing to do this results in errors like sqlite buildtags not being
applied correctly.

Fixes gobuffalo/buffalo#2284
@mattbnz
Copy link
Author

mattbnz commented Jun 30, 2022

The above commit is an example of how I've been able to fix this locally - but no idea if that's something you'd consider for upstreaming?

@sio4
Copy link
Member

sio4 commented Jul 2, 2022

checking... (my reproducing attempt shows some different behavior and also some other issues were found, so it could need more time)

@sio4 sio4 self-assigned this Jul 2, 2022
@sio4 sio4 transferred this issue from gobuffalo/buffalo Jul 2, 2022
@sio4 sio4 linked a pull request Jul 2, 2022 that will close this issue
@sio4 sio4 added the bug Something isn't working label Jul 2, 2022
@sio4
Copy link
Member

sio4 commented Jul 8, 2022

Hi!
The fix was merged into the development branch, but releasing will need more time though.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants