diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e03a6fec..5b2dd213 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,7 +9,7 @@ builds: - amd64 - arm64 ldflags: - - -X github.com/envelope-zero/backend/v5/pkg/router.version={{.Version}} + - -X github.com/envelope-zero/backend/v5/internal/router.version={{.Version}} snapshot: name_template: "{{ incpatch .Version }}-next" diff --git a/Makefile b/Makefile index 32f2c785..0ed8a8ba 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ coverage: test VERSION ?= $(shell git rev-parse HEAD) .PHONY: build build: - go build -ldflags "-X github.com/envelope-zero/backend/v5/pkg/router.version=${VERSION}" + go build -ldflags "-X github.com/envelope-zero/backend/v5/internal/router.version=${VERSION}" .PHONY: docs docs: diff --git a/pkg/controllers/healthz/healthz.go b/internal/controllers/healthz/healthz.go similarity index 88% rename from pkg/controllers/healthz/healthz.go rename to internal/controllers/healthz/healthz.go index 157a754f..9cad8cb2 100644 --- a/pkg/controllers/healthz/healthz.go +++ b/internal/controllers/healthz/healthz.go @@ -3,8 +3,8 @@ package healthz import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/healthz/healthz_test.go b/internal/controllers/healthz/healthz_test.go similarity index 89% rename from pkg/controllers/healthz/healthz_test.go rename to internal/controllers/healthz/healthz_test.go index e2adaab2..b8b18810 100644 --- a/pkg/controllers/healthz/healthz_test.go +++ b/internal/controllers/healthz/healthz_test.go @@ -5,8 +5,8 @@ import ( "net/http/httptest" "testing" - "github.com/envelope-zero/backend/v5/pkg/controllers/healthz" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/controllers/healthz" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/root/root.go b/internal/controllers/root/root.go similarity index 93% rename from pkg/controllers/root/root.go rename to internal/controllers/root/root.go index 82f53530..f41b5c61 100644 --- a/pkg/controllers/root/root.go +++ b/internal/controllers/root/root.go @@ -3,8 +3,8 @@ package root import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/root/root_test.go b/internal/controllers/root/root_test.go similarity index 95% rename from pkg/controllers/root/root_test.go rename to internal/controllers/root/root_test.go index 3af62ae2..5584345f 100644 --- a/pkg/controllers/root/root_test.go +++ b/internal/controllers/root/root_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/envelope-zero/backend/v5/pkg/controllers/root" + "github.com/envelope-zero/backend/v5/internal/controllers/root" "github.com/envelope-zero/backend/v5/test" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/account.go b/internal/controllers/v4/account.go similarity index 99% rename from pkg/controllers/v4/account.go rename to internal/controllers/v4/account.go index ef1cea5e..845b8522 100644 --- a/pkg/controllers/v4/account.go +++ b/internal/controllers/v4/account.go @@ -3,9 +3,9 @@ package v4 import ( "net/http" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" ) diff --git a/pkg/controllers/v4/account_test.go b/internal/controllers/v4/account_test.go similarity index 99% rename from pkg/controllers/v4/account_test.go rename to internal/controllers/v4/account_test.go index 472b1b3b..def368c7 100644 --- a/pkg/controllers/v4/account_test.go +++ b/internal/controllers/v4/account_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/account_types.go b/internal/controllers/v4/account_types.go similarity index 99% rename from pkg/controllers/v4/account_types.go rename to internal/controllers/v4/account_types.go index 5411fa45..c50f97de 100644 --- a/pkg/controllers/v4/account_types.go +++ b/internal/controllers/v4/account_types.go @@ -4,8 +4,8 @@ import ( "fmt" "time" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/budget.go b/internal/controllers/v4/budget.go similarity index 98% rename from pkg/controllers/v4/budget.go rename to internal/controllers/v4/budget.go index 6319526a..9ba64a81 100644 --- a/pkg/controllers/v4/budget.go +++ b/internal/controllers/v4/budget.go @@ -3,8 +3,8 @@ package v4 import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" ) diff --git a/pkg/controllers/v4/budget_test.go b/internal/controllers/v4/budget_test.go similarity index 98% rename from pkg/controllers/v4/budget_test.go rename to internal/controllers/v4/budget_test.go index d1899180..e3cb338b 100644 --- a/pkg/controllers/v4/budget_test.go +++ b/internal/controllers/v4/budget_test.go @@ -6,8 +6,8 @@ import ( "net/http/httptest" "testing" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/budget_types.go b/internal/controllers/v4/budget_types.go similarity index 98% rename from pkg/controllers/v4/budget_types.go rename to internal/controllers/v4/budget_types.go index a2f1f893..99ad69de 100644 --- a/pkg/controllers/v4/budget_types.go +++ b/internal/controllers/v4/budget_types.go @@ -3,7 +3,7 @@ package v4 import ( "fmt" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/category.go b/internal/controllers/v4/category.go similarity index 98% rename from pkg/controllers/v4/category.go rename to internal/controllers/v4/category.go index 1308c8dd..12995954 100644 --- a/pkg/controllers/v4/category.go +++ b/internal/controllers/v4/category.go @@ -3,8 +3,8 @@ package v4 import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" ) diff --git a/pkg/controllers/v4/category_test.go b/internal/controllers/v4/category_test.go similarity index 99% rename from pkg/controllers/v4/category_test.go rename to internal/controllers/v4/category_test.go index 1b37829b..faff4885 100644 --- a/pkg/controllers/v4/category_test.go +++ b/internal/controllers/v4/category_test.go @@ -6,8 +6,8 @@ import ( "net/http/httptest" "testing" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/category_types.go b/internal/controllers/v4/category_types.go similarity index 98% rename from pkg/controllers/v4/category_types.go rename to internal/controllers/v4/category_types.go index 3822cf0b..48c59b81 100644 --- a/pkg/controllers/v4/category_types.go +++ b/internal/controllers/v4/category_types.go @@ -3,8 +3,8 @@ package v4 import ( "fmt" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "gorm.io/gorm" diff --git a/pkg/controllers/v4/cleanup.go b/internal/controllers/v4/cleanup.go similarity index 96% rename from pkg/controllers/v4/cleanup.go rename to internal/controllers/v4/cleanup.go index f7b6e00e..36565d77 100644 --- a/pkg/controllers/v4/cleanup.go +++ b/internal/controllers/v4/cleanup.go @@ -3,7 +3,7 @@ package v4 import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/cleanup_test.go b/internal/controllers/v4/cleanup_test.go similarity index 97% rename from pkg/controllers/v4/cleanup_test.go rename to internal/controllers/v4/cleanup_test.go index e2a3e9e3..61f28d04 100644 --- a/pkg/controllers/v4/cleanup_test.go +++ b/internal/controllers/v4/cleanup_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" "github.com/envelope-zero/backend/v5/test" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/envelope.go b/internal/controllers/v4/envelope.go similarity index 98% rename from pkg/controllers/v4/envelope.go rename to internal/controllers/v4/envelope.go index 4424bc66..76d64a8a 100644 --- a/pkg/controllers/v4/envelope.go +++ b/internal/controllers/v4/envelope.go @@ -3,9 +3,9 @@ package v4 import ( "net/http" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" ) diff --git a/pkg/controllers/v4/envelope_test.go b/internal/controllers/v4/envelope_test.go similarity index 99% rename from pkg/controllers/v4/envelope_test.go rename to internal/controllers/v4/envelope_test.go index e18e21a1..45e69af3 100644 --- a/pkg/controllers/v4/envelope_test.go +++ b/internal/controllers/v4/envelope_test.go @@ -6,8 +6,8 @@ import ( "net/http/httptest" "testing" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/envelope_types.go b/internal/controllers/v4/envelope_types.go similarity index 98% rename from pkg/controllers/v4/envelope_types.go rename to internal/controllers/v4/envelope_types.go index 1a3f7836..45d9e8fb 100644 --- a/pkg/controllers/v4/envelope_types.go +++ b/internal/controllers/v4/envelope_types.go @@ -3,8 +3,8 @@ package v4 import ( "fmt" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" ) diff --git a/pkg/controllers/v4/errors.go b/internal/controllers/v4/errors.go similarity index 96% rename from pkg/controllers/v4/errors.go rename to internal/controllers/v4/errors.go index c5ba6419..2b4d0fc2 100644 --- a/pkg/controllers/v4/errors.go +++ b/internal/controllers/v4/errors.go @@ -4,7 +4,7 @@ import ( "errors" "net/http" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" ) type httpError struct { diff --git a/pkg/controllers/v4/export.go b/internal/controllers/v4/export.go similarity index 91% rename from pkg/controllers/v4/export.go rename to internal/controllers/v4/export.go index 624261dd..51994d04 100644 --- a/pkg/controllers/v4/export.go +++ b/internal/controllers/v4/export.go @@ -6,8 +6,8 @@ import ( "reflect" "time" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/export_test.go b/internal/controllers/v4/export_test.go similarity index 93% rename from pkg/controllers/v4/export_test.go rename to internal/controllers/v4/export_test.go index 6fc94d4d..9aa80869 100644 --- a/pkg/controllers/v4/export_test.go +++ b/internal/controllers/v4/export_test.go @@ -5,8 +5,8 @@ import ( "net/http" "time" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/controllers/v4/export_types.go b/internal/controllers/v4/export_types.go similarity index 100% rename from pkg/controllers/v4/export_types.go rename to internal/controllers/v4/export_types.go diff --git a/pkg/controllers/v4/filters.go b/internal/controllers/v4/filters.go similarity index 100% rename from pkg/controllers/v4/filters.go rename to internal/controllers/v4/filters.go diff --git a/pkg/controllers/v4/goal.go b/internal/controllers/v4/goal.go similarity index 98% rename from pkg/controllers/v4/goal.go rename to internal/controllers/v4/goal.go index e7ca9698..fc2868cf 100644 --- a/pkg/controllers/v4/goal.go +++ b/internal/controllers/v4/goal.go @@ -3,10 +3,10 @@ package v4 import ( "net/http" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" ) diff --git a/pkg/controllers/v4/goal_test.go b/internal/controllers/v4/goal_test.go similarity index 98% rename from pkg/controllers/v4/goal_test.go rename to internal/controllers/v4/goal_test.go index 683070bc..2765f717 100644 --- a/pkg/controllers/v4/goal_test.go +++ b/internal/controllers/v4/goal_test.go @@ -5,10 +5,10 @@ import ( "net/http" "testing" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/goal_types.go b/internal/controllers/v4/goal_types.go similarity index 99% rename from pkg/controllers/v4/goal_types.go rename to internal/controllers/v4/goal_types.go index d4cd9f7e..7be7522d 100644 --- a/pkg/controllers/v4/goal_types.go +++ b/internal/controllers/v4/goal_types.go @@ -3,9 +3,9 @@ package v4 import ( "fmt" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/import.go b/internal/controllers/v4/import.go similarity index 97% rename from pkg/controllers/v4/import.go rename to internal/controllers/v4/import.go index cea50b01..0a2d94e3 100644 --- a/pkg/controllers/v4/import.go +++ b/internal/controllers/v4/import.go @@ -7,12 +7,12 @@ import ( "net/http" "strings" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/importer" + ynabimport "github.com/envelope-zero/backend/v5/internal/importer/parser/ynab-import" + "github.com/envelope-zero/backend/v5/internal/importer/parser/ynab4" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/importer" - ynabimport "github.com/envelope-zero/backend/v5/pkg/importer/parser/ynab-import" - "github.com/envelope-zero/backend/v5/pkg/importer/parser/ynab4" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/ryanuber/go-glob" diff --git a/pkg/controllers/v4/import_test.go b/internal/controllers/v4/import_test.go similarity index 99% rename from pkg/controllers/v4/import_test.go rename to internal/controllers/v4/import_test.go index 08b4d2fc..244695be 100644 --- a/pkg/controllers/v4/import_test.go +++ b/internal/controllers/v4/import_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/import_types.go b/internal/controllers/v4/import_types.go similarity index 96% rename from pkg/controllers/v4/import_types.go rename to internal/controllers/v4/import_types.go index acc3ff6c..2932b85f 100644 --- a/pkg/controllers/v4/import_types.go +++ b/internal/controllers/v4/import_types.go @@ -1,7 +1,7 @@ package v4 import ( - "github.com/envelope-zero/backend/v5/pkg/importer" + "github.com/envelope-zero/backend/v5/internal/importer" "github.com/gin-gonic/gin" "github.com/google/uuid" ) diff --git a/pkg/controllers/v4/match_rule.go b/internal/controllers/v4/match_rule.go similarity index 98% rename from pkg/controllers/v4/match_rule.go rename to internal/controllers/v4/match_rule.go index 3c69b699..a5181b35 100644 --- a/pkg/controllers/v4/match_rule.go +++ b/internal/controllers/v4/match_rule.go @@ -6,9 +6,9 @@ import ( "golang.org/x/exp/slices" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/match_rule_test.go b/internal/controllers/v4/match_rule_test.go similarity index 98% rename from pkg/controllers/v4/match_rule_test.go rename to internal/controllers/v4/match_rule_test.go index 1846cfb6..0f7fc1f7 100644 --- a/pkg/controllers/v4/match_rule_test.go +++ b/internal/controllers/v4/match_rule_test.go @@ -5,9 +5,9 @@ import ( "net/http" "testing" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/match_rule_types.go b/internal/controllers/v4/match_rule_types.go similarity index 98% rename from pkg/controllers/v4/match_rule_types.go rename to internal/controllers/v4/match_rule_types.go index bb1cf9e8..74dd0148 100644 --- a/pkg/controllers/v4/match_rule_types.go +++ b/internal/controllers/v4/match_rule_types.go @@ -3,8 +3,8 @@ package v4 import ( "fmt" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" ) diff --git a/pkg/controllers/v4/month.go b/internal/controllers/v4/month.go similarity index 99% rename from pkg/controllers/v4/month.go rename to internal/controllers/v4/month.go index a268fa59..9c99003a 100644 --- a/pkg/controllers/v4/month.go +++ b/internal/controllers/v4/month.go @@ -5,9 +5,9 @@ import ( "fmt" "net/http" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/month_config.go b/internal/controllers/v4/month_config.go similarity index 97% rename from pkg/controllers/v4/month_config.go rename to internal/controllers/v4/month_config.go index 3b80aa13..fac028a3 100644 --- a/pkg/controllers/v4/month_config.go +++ b/internal/controllers/v4/month_config.go @@ -4,9 +4,9 @@ import ( "errors" "net/http" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/month_config_test.go b/internal/controllers/v4/month_config_test.go similarity index 97% rename from pkg/controllers/v4/month_config_test.go rename to internal/controllers/v4/month_config_test.go index c541790a..da9e3418 100644 --- a/pkg/controllers/v4/month_config_test.go +++ b/internal/controllers/v4/month_config_test.go @@ -6,9 +6,9 @@ import ( "testing" "time" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/month_config_types.go b/internal/controllers/v4/month_config_types.go similarity index 98% rename from pkg/controllers/v4/month_config_types.go rename to internal/controllers/v4/month_config_types.go index 66a74ec5..5e6b9d63 100644 --- a/pkg/controllers/v4/month_config_types.go +++ b/internal/controllers/v4/month_config_types.go @@ -3,8 +3,8 @@ package v4 import ( "fmt" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/month_test.go b/internal/controllers/v4/month_test.go similarity index 99% rename from pkg/controllers/v4/month_test.go rename to internal/controllers/v4/month_test.go index 854c8e32..4688529d 100644 --- a/pkg/controllers/v4/month_test.go +++ b/internal/controllers/v4/month_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/responses.go b/internal/controllers/v4/responses.go similarity index 100% rename from pkg/controllers/v4/responses.go rename to internal/controllers/v4/responses.go diff --git a/pkg/controllers/v4/root.go b/internal/controllers/v4/root.go similarity index 95% rename from pkg/controllers/v4/root.go rename to internal/controllers/v4/root.go index 987d8176..8f22d90e 100644 --- a/pkg/controllers/v4/root.go +++ b/internal/controllers/v4/root.go @@ -3,8 +3,8 @@ package v4 import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/v4/root_test.go b/internal/controllers/v4/root_test.go similarity index 93% rename from pkg/controllers/v4/root_test.go rename to internal/controllers/v4/root_test.go index dc0a3ab1..ceb6db9e 100644 --- a/pkg/controllers/v4/root_test.go +++ b/internal/controllers/v4/root_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" "github.com/envelope-zero/backend/v5/test" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" diff --git a/pkg/controllers/v4/test_list_test.go b/internal/controllers/v4/test_list_test.go similarity index 100% rename from pkg/controllers/v4/test_list_test.go rename to internal/controllers/v4/test_list_test.go diff --git a/pkg/controllers/v4/test_options_test.go b/internal/controllers/v4/test_options_test.go similarity index 100% rename from pkg/controllers/v4/test_options_test.go rename to internal/controllers/v4/test_options_test.go diff --git a/pkg/controllers/v4/test_suite_test.go b/internal/controllers/v4/test_suite_test.go similarity index 95% rename from pkg/controllers/v4/test_suite_test.go rename to internal/controllers/v4/test_suite_test.go index 5d15a9b7..80ba99ac 100644 --- a/pkg/controllers/v4/test_suite_test.go +++ b/internal/controllers/v4/test_suite_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/stretchr/testify/suite" ) diff --git a/pkg/controllers/v4/transaction.go b/internal/controllers/v4/transaction.go similarity index 99% rename from pkg/controllers/v4/transaction.go rename to internal/controllers/v4/transaction.go index d0d31cef..a8695150 100644 --- a/pkg/controllers/v4/transaction.go +++ b/internal/controllers/v4/transaction.go @@ -5,9 +5,9 @@ import ( "net/http" "time" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "golang.org/x/exp/slices" "gorm.io/gorm" diff --git a/pkg/controllers/v4/transaction_test.go b/internal/controllers/v4/transaction_test.go similarity index 99% rename from pkg/controllers/v4/transaction_test.go rename to internal/controllers/v4/transaction_test.go index 7b69f6fa..fe92490e 100644 --- a/pkg/controllers/v4/transaction_test.go +++ b/internal/controllers/v4/transaction_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + "github.com/envelope-zero/backend/v5/internal/httputil" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - "github.com/envelope-zero/backend/v5/pkg/httputil" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/transaction_types.go b/internal/controllers/v4/transaction_types.go similarity index 99% rename from pkg/controllers/v4/transaction_types.go rename to internal/controllers/v4/transaction_types.go index 41c36ab3..2d28fe61 100644 --- a/pkg/controllers/v4/transaction_types.go +++ b/internal/controllers/v4/transaction_types.go @@ -4,9 +4,9 @@ import ( "fmt" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" ez_uuid "github.com/envelope-zero/backend/v5/internal/uuid" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/shopspring/decimal" diff --git a/pkg/controllers/v4/types.go b/internal/controllers/v4/types.go similarity index 100% rename from pkg/controllers/v4/types.go rename to internal/controllers/v4/types.go diff --git a/pkg/controllers/version/version.go b/internal/controllers/version/version.go similarity index 95% rename from pkg/controllers/version/version.go rename to internal/controllers/version/version.go index 1ebcc493..25403c89 100644 --- a/pkg/controllers/version/version.go +++ b/internal/controllers/version/version.go @@ -3,7 +3,7 @@ package version import ( "net/http" - "github.com/envelope-zero/backend/v5/pkg/httputil" + "github.com/envelope-zero/backend/v5/internal/httputil" "github.com/gin-gonic/gin" ) diff --git a/pkg/controllers/version/version_test.go b/internal/controllers/version/version_test.go similarity index 94% rename from pkg/controllers/version/version_test.go rename to internal/controllers/version/version_test.go index c631567b..f6142936 100644 --- a/pkg/controllers/version/version_test.go +++ b/internal/controllers/version/version_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/envelope-zero/backend/v5/pkg/controllers/version" + "github.com/envelope-zero/backend/v5/internal/controllers/version" "github.com/envelope-zero/backend/v5/test" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" diff --git a/pkg/httputil/errors.go b/internal/httputil/errors.go similarity index 100% rename from pkg/httputil/errors.go rename to internal/httputil/errors.go diff --git a/pkg/httputil/options.go b/internal/httputil/options.go similarity index 100% rename from pkg/httputil/options.go rename to internal/httputil/options.go diff --git a/pkg/httputil/options_test.go b/internal/httputil/options_test.go similarity index 98% rename from pkg/httputil/options_test.go rename to internal/httputil/options_test.go index 37eb8fa7..515569fb 100644 --- a/pkg/httputil/options_test.go +++ b/internal/httputil/options_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/envelope-zero/backend/v5/pkg/httputil" + "github.com/envelope-zero/backend/v5/internal/httputil" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) diff --git a/pkg/httputil/query.go b/internal/httputil/query.go similarity index 100% rename from pkg/httputil/query.go rename to internal/httputil/query.go diff --git a/pkg/httputil/query_test.go b/internal/httputil/query_test.go similarity index 97% rename from pkg/httputil/query_test.go rename to internal/httputil/query_test.go index 5825cfbb..f8f6f198 100644 --- a/pkg/httputil/query_test.go +++ b/internal/httputil/query_test.go @@ -7,7 +7,7 @@ import ( "net/url" "testing" - "github.com/envelope-zero/backend/v5/pkg/httputil" + "github.com/envelope-zero/backend/v5/internal/httputil" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) diff --git a/pkg/httputil/request.go b/internal/httputil/request.go similarity index 100% rename from pkg/httputil/request.go rename to internal/httputil/request.go diff --git a/pkg/httputil/request_test.go b/internal/httputil/request_test.go similarity index 97% rename from pkg/httputil/request_test.go rename to internal/httputil/request_test.go index 71e9f5f1..a6da489a 100644 --- a/pkg/httputil/request_test.go +++ b/internal/httputil/request_test.go @@ -6,7 +6,7 @@ import ( "net/http/httptest" "testing" - "github.com/envelope-zero/backend/v5/pkg/httputil" + "github.com/envelope-zero/backend/v5/internal/httputil" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) diff --git a/pkg/importer/README.md b/internal/importer/README.md similarity index 100% rename from pkg/importer/README.md rename to internal/importer/README.md diff --git a/pkg/importer/creator.go b/internal/importer/creator.go similarity index 98% rename from pkg/importer/creator.go rename to internal/importer/creator.go index 107cd9dc..ae02eb0a 100644 --- a/pkg/importer/creator.go +++ b/internal/importer/creator.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/google/uuid" "github.com/shopspring/decimal" "golang.org/x/exp/slices" diff --git a/pkg/importer/helpers/sha256.go b/internal/importer/helpers/sha256.go similarity index 100% rename from pkg/importer/helpers/sha256.go rename to internal/importer/helpers/sha256.go diff --git a/pkg/importer/helpers/sha256_test.go b/internal/importer/helpers/sha256_test.go similarity index 81% rename from pkg/importer/helpers/sha256_test.go rename to internal/importer/helpers/sha256_test.go index d583f608..a2321440 100644 --- a/pkg/importer/helpers/sha256_test.go +++ b/internal/importer/helpers/sha256_test.go @@ -3,7 +3,7 @@ package helpers_test import ( "testing" - "github.com/envelope-zero/backend/v5/pkg/importer/helpers" + "github.com/envelope-zero/backend/v5/internal/importer/helpers" "github.com/stretchr/testify/assert" ) diff --git a/pkg/importer/parser/ynab-import/README.md b/internal/importer/parser/ynab-import/README.md similarity index 100% rename from pkg/importer/parser/ynab-import/README.md rename to internal/importer/parser/ynab-import/README.md diff --git a/pkg/importer/parser/ynab-import/parse.go b/internal/importer/parser/ynab-import/parse.go similarity index 94% rename from pkg/importer/parser/ynab-import/parse.go rename to internal/importer/parser/ynab-import/parse.go index b67743f1..dc5b9078 100644 --- a/pkg/importer/parser/ynab-import/parse.go +++ b/internal/importer/parser/ynab-import/parse.go @@ -8,10 +8,10 @@ import ( "strings" "time" + "github.com/envelope-zero/backend/v5/internal/importer" + "github.com/envelope-zero/backend/v5/internal/importer/helpers" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/importer" - "github.com/envelope-zero/backend/v5/pkg/importer/helpers" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/shopspring/decimal" ) diff --git a/pkg/importer/parser/ynab-import/parse_test.go b/internal/importer/parser/ynab-import/parse_test.go similarity index 87% rename from pkg/importer/parser/ynab-import/parse_test.go rename to internal/importer/parser/ynab-import/parse_test.go index f5068f18..7013c8e7 100644 --- a/pkg/importer/parser/ynab-import/parse_test.go +++ b/internal/importer/parser/ynab-import/parse_test.go @@ -7,7 +7,7 @@ import ( "os" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -26,7 +26,7 @@ func TestParse(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - f, err := os.OpenFile(fmt.Sprintf("../../../../testdata/importer/ynab-import/%s", tt.file), os.O_RDONLY, 0o400) + f, err := os.OpenFile(fmt.Sprintf("../../../../test/data/importer/ynab-import/%s", tt.file), os.O_RDONLY, 0o400) if err != nil { assert.FailNow(t, "Failed to open the test file", err) } @@ -44,7 +44,7 @@ func TestParse(t *testing.T) { // TestReadError verifies that the csvReadError helper method returns the correct result. func TestReadError(t *testing.T) { - f, err := os.OpenFile(fmt.Sprintf("../../../../testdata/importer/ynab-import/%s", "comdirect-ynap.csv"), os.O_RDONLY, 0o400) + f, err := os.OpenFile(fmt.Sprintf("../../../../test/data/importer/ynab-import/%s", "comdirect-ynap.csv"), os.O_RDONLY, 0o400) if err != nil { assert.FailNow(t, "Failed to open the test file", err) } @@ -71,7 +71,7 @@ func TestErrors(t *testing.T) { } for _, tt := range tests { - f, err := os.OpenFile(fmt.Sprintf("../../../../testdata/importer/ynab-import/%s", tt.file), os.O_RDONLY, 0o400) + f, err := os.OpenFile(fmt.Sprintf("../../../../test/data/importer/ynab-import/%s", tt.file), os.O_RDONLY, 0o400) if err != nil { assert.FailNow(t, "Failed to open the test file", err) } diff --git a/pkg/importer/parser/ynab4/README.md b/internal/importer/parser/ynab4/README.md similarity index 100% rename from pkg/importer/parser/ynab4/README.md rename to internal/importer/parser/ynab4/README.md diff --git a/pkg/importer/parser/ynab4/parse.go b/internal/importer/parser/ynab4/parse.go similarity index 99% rename from pkg/importer/parser/ynab4/parse.go rename to internal/importer/parser/ynab4/parse.go index 2be7a7ed..b9d9a93f 100644 --- a/pkg/importer/parser/ynab4/parse.go +++ b/internal/importer/parser/ynab4/parse.go @@ -13,9 +13,9 @@ import ( "github.com/envelope-zero/backend/v5/internal/types" "github.com/google/uuid" - "github.com/envelope-zero/backend/v5/pkg/importer" - "github.com/envelope-zero/backend/v5/pkg/importer/helpers" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/importer" + "github.com/envelope-zero/backend/v5/internal/importer/helpers" + "github.com/envelope-zero/backend/v5/internal/models" "golang.org/x/exp/maps" "golang.org/x/exp/slices" "golang.org/x/text/currency" diff --git a/pkg/importer/parser/ynab4/parse_test.go b/internal/importer/parser/ynab4/parse_test.go similarity index 97% rename from pkg/importer/parser/ynab4/parse_test.go rename to internal/importer/parser/ynab4/parse_test.go index 5612c06e..3227a3ac 100644 --- a/pkg/importer/parser/ynab4/parse_test.go +++ b/internal/importer/parser/ynab4/parse_test.go @@ -11,10 +11,10 @@ import ( "testing/iotest" "time" + "github.com/envelope-zero/backend/v5/internal/importer" + "github.com/envelope-zero/backend/v5/internal/importer/parser/ynab4" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/importer" - "github.com/envelope-zero/backend/v5/pkg/importer/parser/ynab4" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/envelope-zero/backend/v5/test" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" @@ -65,7 +65,7 @@ func TestParseFail(t *testing.T) { } for _, tt := range tests { - f, err := os.OpenFile(fmt.Sprintf("../../../../testdata/importer/%s.yfull", tt.name), os.O_RDONLY, 0o400) + f, err := os.OpenFile(fmt.Sprintf("../../../../test/data/importer/%s.yfull", tt.name), os.O_RDONLY, 0o400) if err != nil { assert.FailNow(t, "Failed to open the test file", err) } @@ -78,10 +78,10 @@ func TestParseFail(t *testing.T) { // TestParse parses a full budget and then verifies that all resources exist. // -// Screenshots for the Budget.yfull file opened in YNAB 4 are in the testdata/importer directory +// Screenshots for the Budget.yfull file opened in YNAB 4 are in the test/data/importer directory // for easier verification of future features and bugs. func TestParse(t *testing.T) { - f, err := os.OpenFile("../../../../testdata/importer/Budget.yfull", os.O_RDONLY, 0o400) + f, err := os.OpenFile("../../../../test/data/importer/Budget.yfull", os.O_RDONLY, 0o400) require.Nil(t, err, "Failed to open the test file: %w", err) // Call the parser diff --git a/pkg/importer/parser/ynab4/types.go b/internal/importer/parser/ynab4/types.go similarity index 98% rename from pkg/importer/parser/ynab4/types.go rename to internal/importer/parser/ynab4/types.go index 59ab068b..4ef6f5c2 100644 --- a/pkg/importer/parser/ynab4/types.go +++ b/internal/importer/parser/ynab4/types.go @@ -21,7 +21,7 @@ type IDToEnvelope struct { Envelope string } -// This has been converted from testdata/importer/Budget.yfull with the help of +// This has been converted from test/data/importer/Budget.yfull with the help of // https://mholt.github.io/json-to-go/ // // Unused fields have been removed to keep the struct as small as possible. diff --git a/pkg/importer/types.go b/internal/importer/types.go similarity index 98% rename from pkg/importer/types.go rename to internal/importer/types.go index 2a2d4c92..c0be5fb6 100644 --- a/pkg/importer/types.go +++ b/internal/importer/types.go @@ -1,8 +1,8 @@ package importer import ( + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/google/uuid" ) diff --git a/pkg/models/account.go b/internal/models/account.go similarity index 100% rename from pkg/models/account.go rename to internal/models/account.go diff --git a/pkg/models/account_test.go b/internal/models/account_test.go similarity index 99% rename from pkg/models/account_test.go rename to internal/models/account_test.go index 8fba06f1..b59b988f 100644 --- a/pkg/models/account_test.go +++ b/internal/models/account_test.go @@ -6,8 +6,8 @@ import ( "strings" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/google/uuid" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" diff --git a/pkg/models/budget.go b/internal/models/budget.go similarity index 100% rename from pkg/models/budget.go rename to internal/models/budget.go diff --git a/pkg/models/budget_test.go b/internal/models/budget_test.go similarity index 99% rename from pkg/models/budget_test.go rename to internal/models/budget_test.go index f5d4221b..9faec448 100644 --- a/pkg/models/budget_test.go +++ b/internal/models/budget_test.go @@ -5,8 +5,8 @@ import ( "strings" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/models/category.go b/internal/models/category.go similarity index 100% rename from pkg/models/category.go rename to internal/models/category.go diff --git a/pkg/models/category_test.go b/internal/models/category_test.go similarity index 98% rename from pkg/models/category_test.go rename to internal/models/category_test.go index 53a6d3b2..1dacb1a7 100644 --- a/pkg/models/category_test.go +++ b/internal/models/category_test.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/models/database.go b/internal/models/database.go similarity index 100% rename from pkg/models/database.go rename to internal/models/database.go diff --git a/pkg/models/database_test.go b/internal/models/database_test.go similarity index 88% rename from pkg/models/database_test.go rename to internal/models/database_test.go index 0a856cd2..d9c1a8ff 100644 --- a/pkg/models/database_test.go +++ b/internal/models/database_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/stretchr/testify/require" ) @@ -28,7 +28,7 @@ func TestMigrateWithExistingDB(t *testing.T) { func TestV4V5Migration(t *testing.T) { dbFile := test.TmpFile(t) - input, err := os.ReadFile("../../testdata/migrations/v4-v5.db") + input, err := os.ReadFile("../../test/data/migrations/v4-v5.db") if err != nil { t.Error("Could not read test database") } diff --git a/pkg/models/envelope.go b/internal/models/envelope.go similarity index 100% rename from pkg/models/envelope.go rename to internal/models/envelope.go diff --git a/pkg/models/envelope_test.go b/internal/models/envelope_test.go similarity index 99% rename from pkg/models/envelope_test.go rename to internal/models/envelope_test.go index 66811255..e46c56c3 100644 --- a/pkg/models/envelope_test.go +++ b/internal/models/envelope_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/models/errors.go b/internal/models/errors.go similarity index 100% rename from pkg/models/errors.go rename to internal/models/errors.go diff --git a/pkg/models/goal.go b/internal/models/goal.go similarity index 100% rename from pkg/models/goal.go rename to internal/models/goal.go diff --git a/pkg/models/goal_test.go b/internal/models/goal_test.go similarity index 98% rename from pkg/models/goal_test.go rename to internal/models/goal_test.go index f9b7b9d7..e6fb7f8b 100644 --- a/pkg/models/goal_test.go +++ b/internal/models/goal_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/google/uuid" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" diff --git a/pkg/models/interfaces.go b/internal/models/interfaces.go similarity index 100% rename from pkg/models/interfaces.go rename to internal/models/interfaces.go diff --git a/pkg/models/logger.go b/internal/models/logger.go similarity index 100% rename from pkg/models/logger.go rename to internal/models/logger.go diff --git a/pkg/models/match_rule.go b/internal/models/match_rule.go similarity index 100% rename from pkg/models/match_rule.go rename to internal/models/match_rule.go diff --git a/pkg/models/match_rule_test.go b/internal/models/match_rule_test.go similarity index 97% rename from pkg/models/match_rule_test.go rename to internal/models/match_rule_test.go index 207912c1..7871b788 100644 --- a/pkg/models/match_rule_test.go +++ b/internal/models/match_rule_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/models/model.go b/internal/models/model.go similarity index 100% rename from pkg/models/model.go rename to internal/models/model.go diff --git a/pkg/models/month_config.go b/internal/models/month_config.go similarity index 100% rename from pkg/models/month_config.go rename to internal/models/month_config.go diff --git a/pkg/models/month_config_test.go b/internal/models/month_config_test.go similarity index 96% rename from pkg/models/month_config_test.go rename to internal/models/month_config_test.go index 28cd2539..9495702a 100644 --- a/pkg/models/month_config_test.go +++ b/internal/models/month_config_test.go @@ -5,8 +5,8 @@ import ( "strings" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/models/test_suite_test.go b/internal/models/test_suite_test.go similarity index 98% rename from pkg/models/test_suite_test.go rename to internal/models/test_suite_test.go index 861eebe7..d05176ab 100644 --- a/pkg/models/test_suite_test.go +++ b/internal/models/test_suite_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/test" "github.com/google/uuid" "github.com/stretchr/testify/suite" diff --git a/pkg/models/transaction.go b/internal/models/transaction.go similarity index 100% rename from pkg/models/transaction.go rename to internal/models/transaction.go diff --git a/pkg/models/transaction_test.go b/internal/models/transaction_test.go similarity index 99% rename from pkg/models/transaction_test.go rename to internal/models/transaction_test.go index 09f04be8..a13db9e8 100644 --- a/pkg/models/transaction_test.go +++ b/internal/models/transaction_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/envelope-zero/backend/v5/internal/types" - "github.com/envelope-zero/backend/v5/pkg/models" "github.com/google/uuid" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" diff --git a/pkg/router/middleware.go b/internal/router/middleware.go similarity index 97% rename from pkg/router/middleware.go rename to internal/router/middleware.go index 818708a2..6c97db7b 100644 --- a/pkg/router/middleware.go +++ b/internal/router/middleware.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/envelope-zero/backend/v5/pkg/models" + "github.com/envelope-zero/backend/v5/internal/models" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/router/middleware_test.go b/internal/router/middleware_test.go similarity index 85% rename from pkg/router/middleware_test.go rename to internal/router/middleware_test.go index 7cee0406..cc0c6ae7 100644 --- a/pkg/router/middleware_test.go +++ b/internal/router/middleware_test.go @@ -6,8 +6,8 @@ import ( "net/url" "testing" - "github.com/envelope-zero/backend/v5/pkg/models" - "github.com/envelope-zero/backend/v5/pkg/router" + "github.com/envelope-zero/backend/v5/internal/models" + "github.com/envelope-zero/backend/v5/internal/router" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) diff --git a/internal/router/router.go b/internal/router/router.go new file mode 100644 index 00000000..960a5a6e --- /dev/null +++ b/internal/router/router.go @@ -0,0 +1,168 @@ +package router + +import ( + "net/http" + "net/url" + "os" + "strings" + + docs "github.com/envelope-zero/backend/v5/api" + "github.com/envelope-zero/backend/v5/internal/controllers/healthz" + "github.com/envelope-zero/backend/v5/internal/controllers/root" + v4 "github.com/envelope-zero/backend/v5/internal/controllers/v4" + version_controller "github.com/envelope-zero/backend/v5/internal/controllers/version" + "github.com/gin-contrib/cors" + "github.com/gin-contrib/logger" + "github.com/gin-contrib/pprof" + "github.com/gin-contrib/requestid" + "github.com/gin-gonic/gin" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" +) + +// Version of the API +// +// This is set at build time, see Makefile. +var version = "0.0.0" + +// Config sets up the router, returns a teardown function +// and an error. +func Config(url *url.URL) (*gin.Engine, func(), error) { + // Set up prometheus metrics + if err := registerPrometheusMetrics(); err != nil { + return gin.New(), func() {}, err + } + + // Set up the router and middlewares + r := gin.New() + + // Don’t process X-Forwarded-For header as we do not do anything with + // client IPs + r.ForwardedByClientIP = false + + // Send a HTTP 405 (Method not allowed) for all paths where there is + // a handler, but not for the specific method used + r.HandleMethodNotAllowed = true + + r.Use(gin.Recovery()) + r.Use(requestid.New()) + r.Use(URLMiddleware(url)) + r.Use(MetricsMiddleware()) + r.NoMethod(func(c *gin.Context) { + c.JSON(http.StatusMethodNotAllowed, gin.H{ + "error": "This HTTP method is not allowed for the endpoint you called", + }) + }) + + // CORS settings + allowOrigins, ok := os.LookupEnv("CORS_ALLOW_ORIGINS") + if ok { + log.Debug().Str("CORS Allowed Origins", allowOrigins).Msg("Router") + + r.Use(cors.New(cors.Config{ + AllowOrigins: strings.Fields(allowOrigins), + AllowMethods: []string{"OPTIONS", "GET", "POST", "PATCH", "DELETE"}, + AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, + AllowCredentials: true, + })) + } + + // Disable the gin debug route printing as it clutters logs (and test logs) + gin.DebugPrintRouteFunc = func(_, _, _ string, _ int) {} + + // Don’t trust any proxy. We do not process any client IPs, + // therefore we don’t need to trust anyone here. + _ = r.SetTrustedProxies([]string{}) + + log.Debug().Str("API Base URL", url.String()).Str("Host", url.Host).Str("Path", url.Path).Msg("Router") + log.Info().Str("version", version).Msg("Router") + + docs.SwaggerInfo.Host = url.Host + docs.SwaggerInfo.BasePath = url.Path + docs.SwaggerInfo.Title = "Envelope Zero" + docs.SwaggerInfo.Version = version + docs.SwaggerInfo.Description = "The backend for Envelope Zero, a zero based envelope budgeting solution. Check out the source code at https://github.com/envelope-zero/backend." + + return r, func() { unregisterPrometheusMetrics() }, nil +} + +// AttachRoutes attaches the API routes to the router group that is passed in +// Separating this from RouterConfig() allows us to attach it to different +// paths for different use cases, e.g. the standalone version. +func AttachRoutes(group *gin.RouterGroup) { + ezLogger := logger.SetLogger( + logger.WithDefaultLevel(zerolog.InfoLevel), + logger.WithClientErrorLevel(zerolog.InfoLevel), + logger.WithServerErrorLevel(zerolog.ErrorLevel), + logger.WithLogger(func(c *gin.Context, logger zerolog.Logger) zerolog.Logger { + return logger.With(). + Str("request-id", requestid.Get(c)). + Str("method", c.Request.Method). + Str("path", c.Request.URL.Path). + Int("status", c.Writer.Status()). + Int("size", c.Writer.Size()). + Str("user-agent", c.Request.UserAgent()). + Logger() + }), + ) + + // skipLogger returns the correct logger for the route + // + // This is either a logger that skips logging or the ezLogger + skipLogger := func(path, envVar string) gin.HandlerFunc { + disable, ok := os.LookupEnv(envVar) + if ok && disable == "true" { + return logger.SetLogger( + logger.WithSkipPath([]string{path}), + ) + } + + return ezLogger + } + + // metrics + group.GET("/metrics", skipLogger("/metrics", "DISABLE_METRICS_LOGS"), gin.WrapH(promhttp.Handler())) + + // healthz + healthzGroup := group.Group("/healthz", skipLogger("/healthz", "DISABLE_HEALTHZ_LOGS")) + healthz.RegisterRoutes(healthzGroup.Group("")) + + // All groups that can disable logs are registered, register logger by default + group.Use(ezLogger) + + // pprof performance profiles + enablePprof, ok := os.LookupEnv("ENABLE_PPROF") + if ok && enablePprof == "true" { + pprof.RouteRegister(group, "debug/pprof") + } + + // Swagger API docs + group.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + + // Unversioned global endpoints + { + root.RegisterRoutes(group.Group("")) + version_controller.RegisterRoutes(group.Group("/version"), version) + } + + // v4 + { + v4Group := group.Group("/v4") + v4.RegisterRootRoutes(v4Group.Group("")) + v4.RegisterAccountRoutes(v4Group.Group("/accounts")) + v4.RegisterBudgetRoutes(v4Group.Group("/budgets")) + v4.RegisterCategoryRoutes(v4Group.Group("/categories")) + v4.RegisterEnvelopeRoutes(v4Group.Group("/envelopes")) + v4.RegisterExportRoutes(v4Group.Group("/export"), version) + v4.RegisterGoalRoutes(v4Group.Group("/goals")) + v4.RegisterImportRoutes(v4Group.Group("/import")) + v4.RegisterMatchRuleRoutes(v4Group.Group("/match-rules")) + v4.RegisterMonthConfigRoutes(v4Group.Group("/envelopes")) + v4.RegisterMonthRoutes(v4Group.Group("/months")) + v4.RegisterTransactionRoutes(v4Group.Group("/transactions")) + } +} diff --git a/internal/router/router_test.go b/internal/router/router_test.go new file mode 100644 index 00000000..73d8ec16 --- /dev/null +++ b/internal/router/router_test.go @@ -0,0 +1,74 @@ +package router_test + +import ( + "net/url" + "os" + "testing" + + "github.com/envelope-zero/backend/v5/internal/router" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func TestGinMode(t *testing.T) { + os.Setenv("GIN_MODE", "debug") + url, _ := url.Parse("http://example.com") + + r, teardown, err := router.Config(url) + defer teardown() + + assert.Nil(t, err, "Error on router initialization") + + router.AttachRoutes(r.Group("/")) + + assert.Nil(t, err, "%T: %v", err, err) + assert.True(t, gin.IsDebugging()) + + os.Unsetenv("GIN_MODE") +} + +func TestPprofOn(t *testing.T) { + os.Setenv("ENABLE_PPROF", "true") + url, _ := url.Parse("http://example.com") + + r, teardown, err := router.Config(url) + defer teardown() + assert.Nil(t, err, "Error on router initialization") + + router.AttachRoutes(r.Group("/")) + + var routes []string + for _, r := range r.Routes() { + routes = append(routes, r.Path) + } + assert.Contains(t, routes, "/debug/pprof/") + + os.Unsetenv("ENABLE_PPROF") +} + +func TestPprofOff(t *testing.T) { + url, _ := url.Parse("http://example.com") + + r, teardown, err := router.Config(url) + defer teardown() + assert.Nil(t, err, "Error on router initialization") + + router.AttachRoutes(r.Group("/")) + + for _, r := range r.Routes() { + assert.NotContains(t, r.Path, "pprof", "pprof routes are registered erroneously! Route: %s", r) + } +} + +// TestCorsSetting checks that setting of CORS works. +// It does not check the actual headers as this is already done in testing of the module. +func TestCorsSetting(t *testing.T) { + os.Setenv("CORS_ALLOW_ORIGINS", "http://localhost:3000 https://example.com") + url, _ := url.Parse("http://example.com") + + _, teardown, err := router.Config(url) + defer teardown() + + assert.Nil(t, err) + os.Unsetenv("CORS_ALLOW_ORIGINS") +} diff --git a/main.go b/main.go index a7c69b3b..7e216d08 100644 --- a/main.go +++ b/main.go @@ -10,8 +10,8 @@ import ( "syscall" "time" - "github.com/envelope-zero/backend/v5/pkg/models" - "github.com/envelope-zero/backend/v5/pkg/router" + "github.com/envelope-zero/backend/v5/internal/models" + "github.com/envelope-zero/backend/v5/internal/router" "github.com/gin-gonic/gin" "github.com/rs/zerolog" "github.com/rs/zerolog/log" diff --git a/pkg/db/db.go b/pkg/db/db.go new file mode 100644 index 00000000..5df43efb --- /dev/null +++ b/pkg/db/db.go @@ -0,0 +1,7 @@ +package db + +import "github.com/envelope-zero/backend/v5/internal/models" + +func Connect(dsn string) error { + return models.Connect(dsn) +} diff --git a/pkg/db/db_test.go b/pkg/db/db_test.go new file mode 100644 index 00000000..2210f077 --- /dev/null +++ b/pkg/db/db_test.go @@ -0,0 +1,16 @@ +package db_test + +import ( + "testing" + + "github.com/envelope-zero/backend/v5/pkg/db" + "github.com/envelope-zero/backend/v5/test" + "github.com/stretchr/testify/require" +) + +func TestConnect(t *testing.T) { + testDB := test.TmpFile(t) + + // Test database connection + require.Nil(t, db.Connect(testDB)) +} diff --git a/pkg/router/router.go b/pkg/router/router.go index a9baeef0..b1499d97 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -1,168 +1,16 @@ package router import ( - "net/http" "net/url" - "os" - "strings" - docs "github.com/envelope-zero/backend/v5/api" - "github.com/envelope-zero/backend/v5/pkg/controllers/healthz" - "github.com/envelope-zero/backend/v5/pkg/controllers/root" - v4 "github.com/envelope-zero/backend/v5/pkg/controllers/v4" - version_controller "github.com/envelope-zero/backend/v5/pkg/controllers/version" - "github.com/gin-contrib/cors" - "github.com/gin-contrib/logger" - "github.com/gin-contrib/pprof" - "github.com/gin-contrib/requestid" + "github.com/envelope-zero/backend/v5/internal/router" "github.com/gin-gonic/gin" - "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" - - swaggerFiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" ) -// Version of the API -// -// This is set at build time, see Makefile. -var version = "0.0.0" - -// Config sets up the router, returns a teardown function -// and an error. -func Config(url *url.URL) (*gin.Engine, func(), error) { - // Set up prometheus metrics - if err := registerPrometheusMetrics(); err != nil { - return gin.New(), func() {}, err - } - - // Set up the router and middlewares - r := gin.New() - - // Don’t process X-Forwarded-For header as we do not do anything with - // client IPs - r.ForwardedByClientIP = false - - // Send a HTTP 405 (Method not allowed) for all paths where there is - // a handler, but not for the specific method used - r.HandleMethodNotAllowed = true - - r.Use(gin.Recovery()) - r.Use(requestid.New()) - r.Use(URLMiddleware(url)) - r.Use(MetricsMiddleware()) - r.NoMethod(func(c *gin.Context) { - c.JSON(http.StatusMethodNotAllowed, gin.H{ - "error": "This HTTP method is not allowed for the endpoint you called", - }) - }) - - // CORS settings - allowOrigins, ok := os.LookupEnv("CORS_ALLOW_ORIGINS") - if ok { - log.Debug().Str("CORS Allowed Origins", allowOrigins).Msg("Router") - - r.Use(cors.New(cors.Config{ - AllowOrigins: strings.Fields(allowOrigins), - AllowMethods: []string{"OPTIONS", "GET", "POST", "PATCH", "DELETE"}, - AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, - AllowCredentials: true, - })) - } - - // Disable the gin debug route printing as it clutters logs (and test logs) - gin.DebugPrintRouteFunc = func(_, _, _ string, _ int) {} - - // Don’t trust any proxy. We do not process any client IPs, - // therefore we don’t need to trust anyone here. - _ = r.SetTrustedProxies([]string{}) - - log.Debug().Str("API Base URL", url.String()).Str("Host", url.Host).Str("Path", url.Path).Msg("Router") - log.Info().Str("version", version).Msg("Router") - - docs.SwaggerInfo.Host = url.Host - docs.SwaggerInfo.BasePath = url.Path - docs.SwaggerInfo.Title = "Envelope Zero" - docs.SwaggerInfo.Version = version - docs.SwaggerInfo.Description = "The backend for Envelope Zero, a zero based envelope budgeting solution. Check out the source code at https://github.com/envelope-zero/backend." - - return r, func() { unregisterPrometheusMetrics() }, nil -} - -// AttachRoutes attaches the API routes to the router group that is passed in -// Separating this from RouterConfig() allows us to attach it to different -// paths for different use cases, e.g. the standalone version. func AttachRoutes(group *gin.RouterGroup) { - ezLogger := logger.SetLogger( - logger.WithDefaultLevel(zerolog.InfoLevel), - logger.WithClientErrorLevel(zerolog.InfoLevel), - logger.WithServerErrorLevel(zerolog.ErrorLevel), - logger.WithLogger(func(c *gin.Context, logger zerolog.Logger) zerolog.Logger { - return logger.With(). - Str("request-id", requestid.Get(c)). - Str("method", c.Request.Method). - Str("path", c.Request.URL.Path). - Int("status", c.Writer.Status()). - Int("size", c.Writer.Size()). - Str("user-agent", c.Request.UserAgent()). - Logger() - }), - ) - - // skipLogger returns the correct logger for the route - // - // This is either a logger that skips logging or the ezLogger - skipLogger := func(path, envVar string) gin.HandlerFunc { - disable, ok := os.LookupEnv(envVar) - if ok && disable == "true" { - return logger.SetLogger( - logger.WithSkipPath([]string{path}), - ) - } - - return ezLogger - } - - // metrics - group.GET("/metrics", skipLogger("/metrics", "DISABLE_METRICS_LOGS"), gin.WrapH(promhttp.Handler())) - - // healthz - healthzGroup := group.Group("/healthz", skipLogger("/healthz", "DISABLE_HEALTHZ_LOGS")) - healthz.RegisterRoutes(healthzGroup.Group("")) - - // All groups that can disable logs are registered, register logger by default - group.Use(ezLogger) - - // pprof performance profiles - enablePprof, ok := os.LookupEnv("ENABLE_PPROF") - if ok && enablePprof == "true" { - pprof.RouteRegister(group, "debug/pprof") - } - - // Swagger API docs - group.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - - // Unversioned global endpoints - { - root.RegisterRoutes(group.Group("")) - version_controller.RegisterRoutes(group.Group("/version"), version) - } + router.AttachRoutes(group) +} - // v4 - { - v4Group := group.Group("/v4") - v4.RegisterRootRoutes(v4Group.Group("")) - v4.RegisterAccountRoutes(v4Group.Group("/accounts")) - v4.RegisterBudgetRoutes(v4Group.Group("/budgets")) - v4.RegisterCategoryRoutes(v4Group.Group("/categories")) - v4.RegisterEnvelopeRoutes(v4Group.Group("/envelopes")) - v4.RegisterExportRoutes(v4Group.Group("/export"), version) - v4.RegisterGoalRoutes(v4Group.Group("/goals")) - v4.RegisterImportRoutes(v4Group.Group("/import")) - v4.RegisterMatchRuleRoutes(v4Group.Group("/match-rules")) - v4.RegisterMonthConfigRoutes(v4Group.Group("/envelopes")) - v4.RegisterMonthRoutes(v4Group.Group("/months")) - v4.RegisterTransactionRoutes(v4Group.Group("/transactions")) - } +func Config(url *url.URL) (*gin.Engine, func(), error) { + return router.Config(url) } diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index d484948a..a95d90d3 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -2,73 +2,19 @@ package router_test import ( "net/url" - "os" "testing" "github.com/envelope-zero/backend/v5/pkg/router" - "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" ) func TestGinMode(t *testing.T) { - os.Setenv("GIN_MODE", "debug") url, _ := url.Parse("http://example.com") r, teardown, err := router.Config(url) defer teardown() assert.Nil(t, err, "Error on router initialization") - router.AttachRoutes(r.Group("/")) - assert.Nil(t, err, "%T: %v", err, err) - assert.True(t, gin.IsDebugging()) - - os.Unsetenv("GIN_MODE") -} - -func TestPprofOn(t *testing.T) { - os.Setenv("ENABLE_PPROF", "true") - url, _ := url.Parse("http://example.com") - - r, teardown, err := router.Config(url) - defer teardown() - assert.Nil(t, err, "Error on router initialization") - - router.AttachRoutes(r.Group("/")) - - var routes []string - for _, r := range r.Routes() { - routes = append(routes, r.Path) - } - assert.Contains(t, routes, "/debug/pprof/") - - os.Unsetenv("ENABLE_PPROF") -} - -func TestPprofOff(t *testing.T) { - url, _ := url.Parse("http://example.com") - - r, teardown, err := router.Config(url) - defer teardown() - assert.Nil(t, err, "Error on router initialization") - - router.AttachRoutes(r.Group("/")) - - for _, r := range r.Routes() { - assert.NotContains(t, r.Path, "pprof", "pprof routes are registered erroneously! Route: %s", r) - } -} - -// TestCorsSetting checks that setting of CORS works. -// It does not check the actual headers as this is already done in testing of the module. -func TestCorsSetting(t *testing.T) { - os.Setenv("CORS_ALLOW_ORIGINS", "http://localhost:3000 https://example.com") - url, _ := url.Parse("http://example.com") - - _, teardown, err := router.Config(url) - defer teardown() - - assert.Nil(t, err) - os.Unsetenv("CORS_ALLOW_ORIGINS") } diff --git a/testdata/importer/Budget.yfull b/test/data/importer/Budget.yfull similarity index 100% rename from testdata/importer/Budget.yfull rename to test/data/importer/Budget.yfull diff --git a/testdata/importer/CorruptMissingTargetTransaction.yfull b/test/data/importer/CorruptMissingTargetTransaction.yfull similarity index 100% rename from testdata/importer/CorruptMissingTargetTransaction.yfull rename to test/data/importer/CorruptMissingTargetTransaction.yfull diff --git a/testdata/importer/CorruptMonthlyBudget.yfull b/test/data/importer/CorruptMonthlyBudget.yfull similarity index 100% rename from testdata/importer/CorruptMonthlyBudget.yfull rename to test/data/importer/CorruptMonthlyBudget.yfull diff --git a/testdata/importer/CorruptNoMatchingTransfer.yfull b/test/data/importer/CorruptNoMatchingTransfer.yfull similarity index 100% rename from testdata/importer/CorruptNoMatchingTransfer.yfull rename to test/data/importer/CorruptNoMatchingTransfer.yfull diff --git a/testdata/importer/CorruptNonParseableHidden.yfull b/test/data/importer/CorruptNonParseableHidden.yfull similarity index 100% rename from testdata/importer/CorruptNonParseableHidden.yfull rename to test/data/importer/CorruptNonParseableHidden.yfull diff --git a/testdata/importer/CorruptNonParseableTransactionDate.yfull b/test/data/importer/CorruptNonParseableTransactionDate.yfull similarity index 100% rename from testdata/importer/CorruptNonParseableTransactionDate.yfull rename to test/data/importer/CorruptNonParseableTransactionDate.yfull diff --git a/testdata/importer/EmptyFile.yfull b/test/data/importer/EmptyFile.yfull similarity index 100% rename from testdata/importer/EmptyFile.yfull rename to test/data/importer/EmptyFile.yfull diff --git a/testdata/importer/account-balances.png b/test/data/importer/account-balances.png similarity index 100% rename from testdata/importer/account-balances.png rename to test/data/importer/account-balances.png diff --git a/testdata/importer/budget.png b/test/data/importer/budget.png similarity index 100% rename from testdata/importer/budget.png rename to test/data/importer/budget.png diff --git a/testdata/importer/hidden-categories.png b/test/data/importer/hidden-categories.png similarity index 100% rename from testdata/importer/hidden-categories.png rename to test/data/importer/hidden-categories.png diff --git a/testdata/importer/scheduled-transactions.png b/test/data/importer/scheduled-transactions.png similarity index 100% rename from testdata/importer/scheduled-transactions.png rename to test/data/importer/scheduled-transactions.png diff --git a/testdata/importer/transactions.png b/test/data/importer/transactions.png similarity index 100% rename from testdata/importer/transactions.png rename to test/data/importer/transactions.png diff --git a/testdata/importer/wrong-name.json b/test/data/importer/wrong-name.json similarity index 100% rename from testdata/importer/wrong-name.json rename to test/data/importer/wrong-name.json diff --git a/testdata/importer/ynab-import/account-find-test.csv b/test/data/importer/ynab-import/account-find-test.csv similarity index 100% rename from testdata/importer/ynab-import/account-find-test.csv rename to test/data/importer/ynab-import/account-find-test.csv diff --git a/testdata/importer/ynab-import/available-from-test.csv b/test/data/importer/ynab-import/available-from-test.csv similarity index 100% rename from testdata/importer/ynab-import/available-from-test.csv rename to test/data/importer/ynab-import/available-from-test.csv diff --git a/testdata/importer/ynab-import/bank2ynab-ynap.csv b/test/data/importer/ynab-import/bank2ynab-ynap.csv similarity index 100% rename from testdata/importer/ynab-import/bank2ynab-ynap.csv rename to test/data/importer/ynab-import/bank2ynab-ynap.csv diff --git a/testdata/importer/ynab-import/comdirect-ynap.csv b/test/data/importer/ynab-import/comdirect-ynap.csv similarity index 100% rename from testdata/importer/ynab-import/comdirect-ynap.csv rename to test/data/importer/ynab-import/comdirect-ynap.csv diff --git a/testdata/importer/ynab-import/empty.csv b/test/data/importer/ynab-import/empty.csv similarity index 100% rename from testdata/importer/ynab-import/empty.csv rename to test/data/importer/ynab-import/empty.csv diff --git a/testdata/importer/ynab-import/error-date.csv b/test/data/importer/ynab-import/error-date.csv similarity index 100% rename from testdata/importer/ynab-import/error-date.csv rename to test/data/importer/ynab-import/error-date.csv diff --git a/testdata/importer/ynab-import/error-decimal-inflow.csv b/test/data/importer/ynab-import/error-decimal-inflow.csv similarity index 100% rename from testdata/importer/ynab-import/error-decimal-inflow.csv rename to test/data/importer/ynab-import/error-decimal-inflow.csv diff --git a/testdata/importer/ynab-import/error-decimal-outflow.csv b/test/data/importer/ynab-import/error-decimal-outflow.csv similarity index 100% rename from testdata/importer/ynab-import/error-decimal-outflow.csv rename to test/data/importer/ynab-import/error-decimal-outflow.csv diff --git a/testdata/importer/ynab-import/error-missing-amount.csv b/test/data/importer/ynab-import/error-missing-amount.csv similarity index 100% rename from testdata/importer/ynab-import/error-missing-amount.csv rename to test/data/importer/ynab-import/error-missing-amount.csv diff --git a/testdata/importer/ynab-import/error-outflow-and-inflow.csv b/test/data/importer/ynab-import/error-outflow-and-inflow.csv similarity index 100% rename from testdata/importer/ynab-import/error-outflow-and-inflow.csv rename to test/data/importer/ynab-import/error-outflow-and-inflow.csv diff --git a/testdata/importer/ynab-import/match-rule-test.csv b/test/data/importer/ynab-import/match-rule-test.csv similarity index 100% rename from testdata/importer/ynab-import/match-rule-test.csv rename to test/data/importer/ynab-import/match-rule-test.csv diff --git a/testdata/importer/ynab-import/rename-rule-test.csv b/test/data/importer/ynab-import/rename-rule-test.csv similarity index 100% rename from testdata/importer/ynab-import/rename-rule-test.csv rename to test/data/importer/ynab-import/rename-rule-test.csv diff --git a/testdata/importer/ynab-import/unparsed-file.csv b/test/data/importer/ynab-import/unparsed-file.csv similarity index 100% rename from testdata/importer/ynab-import/unparsed-file.csv rename to test/data/importer/ynab-import/unparsed-file.csv diff --git a/testdata/importer/ynab-import/wrong-suffix.json b/test/data/importer/ynab-import/wrong-suffix.json similarity index 100% rename from testdata/importer/ynab-import/wrong-suffix.json rename to test/data/importer/ynab-import/wrong-suffix.json diff --git a/testdata/migrations/v4-v5.db b/test/data/migrations/v4-v5.db similarity index 100% rename from testdata/migrations/v4-v5.db rename to test/data/migrations/v4-v5.db diff --git a/test/import.go b/test/import.go index a99ee466..c91c88de 100644 --- a/test/import.go +++ b/test/import.go @@ -11,11 +11,11 @@ import ( "github.com/stretchr/testify/assert" ) -// LoadTestFile loads a test file from the testdata directory +// LoadTestFile loads a test file from the test/data directory // // File contents are returned as a buffer and a map for the HTTP request headers func LoadTestFile(t *testing.T, filePath string) (*bytes.Buffer, map[string]string) { - path := path.Join("../../../testdata", filePath) + path := path.Join("../../../test/data", filePath) body := new(bytes.Buffer) mw := multipart.NewWriter(body) diff --git a/test/request.go b/test/request.go index 3eeb2458..899324ca 100644 --- a/test/request.go +++ b/test/request.go @@ -10,7 +10,7 @@ import ( "reflect" "testing" - "github.com/envelope-zero/backend/v5/pkg/router" + "github.com/envelope-zero/backend/v5/internal/router" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )