Skip to content

Commit

Permalink
chore(pgs): integration tests for web api (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap authored Oct 16, 2024
1 parent 82dc843 commit 72b3683
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
args: -E goimports -E godot --timeout 10m
- name: Run tests
run: |
go test -v ./... -cover -race -coverprofile=coverage.out
PICO_SECRET="danger" go test -v ./... -cover -race -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
build-main:
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion auth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func createMainRoutes() []shared.Route {
return routes
}

func handler(routes []shared.Route, client *Client) shared.ServeFn {
func handler(routes []shared.Route, client *Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var allow []string

Expand Down
282 changes: 282 additions & 0 deletions db/stub/stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
package stub

import (
"database/sql"
"fmt"
"log/slog"
"time"

"github.com/picosh/pico/db"
)

type StubDB struct {
Logger *slog.Logger
}

var _ db.DB = (*StubDB)(nil)

func NewStubDB(logger *slog.Logger) *StubDB {
d := &StubDB{
Logger: logger,
}
d.Logger.Info("Connecting to test database")
return d
}

var notImpl = fmt.Errorf("not implemented")

func (me *StubDB) RegisterUser(username, pubkey, comment string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) RemoveUsers(userIDs []string) error {
return notImpl
}

func (me *StubDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error {
return notImpl
}

func (me *StubDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) {
return nil, notImpl
}

func (me *StubDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) {
return nil, notImpl
}

func (me *StubDB) FindPublicKey(pubkeyID string) (*db.PublicKey, error) {
return nil, notImpl
}

func (me *StubDB) FindKeysForUser(user *db.User) ([]*db.PublicKey, error) {
return []*db.PublicKey{}, notImpl
}

func (me *StubDB) RemoveKeys(keyIDs []string) error {
return notImpl
}

func (me *StubDB) FindSiteAnalytics(space string) (*db.Analytics, error) {
return nil, notImpl
}

func (me *StubDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post, error) {
return []*db.Post{}, notImpl
}

func (me *StubDB) FindUserForKey(username string, key string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) FindUser(userID string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) ValidateName(name string) (bool, error) {
return false, notImpl
}

func (me *StubDB) FindUserForName(name string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) FindUserForNameAndKey(name string, key string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) FindUserForToken(token string) (*db.User, error) {
return nil, notImpl
}

func (me *StubDB) SetUserName(userID string, name string) error {
return notImpl
}

func (me *StubDB) FindPostWithFilename(filename string, persona_id string, space string) (*db.Post, error) {
return nil, notImpl
}

func (me *StubDB) FindPostWithSlug(slug string, user_id string, space string) (*db.Post, error) {
return nil, notImpl
}

func (me *StubDB) FindPost(postID string) (*db.Post, error) {
return nil, notImpl
}

func (me *StubDB) FindAllPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) {
return &db.Paginate[*db.Post]{}, notImpl
}

func (me *StubDB) FindAllUpdatedPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) {
return &db.Paginate[*db.Post]{}, notImpl
}

func (me *StubDB) InsertPost(post *db.Post) (*db.Post, error) {
return nil, notImpl
}

func (me *StubDB) UpdatePost(post *db.Post) (*db.Post, error) {
return nil, notImpl
}

func (me *StubDB) RemovePosts(postIDs []string) error {
return notImpl
}

func (me *StubDB) FindPostsForUser(page *db.Pager, userID string, space string) (*db.Paginate[*db.Post], error) {
return &db.Paginate[*db.Post]{}, notImpl
}

func (me *StubDB) FindAllPostsForUser(userID string, space string) ([]*db.Post, error) {
return []*db.Post{}, notImpl
}

func (me *StubDB) FindPosts() ([]*db.Post, error) {
return []*db.Post{}, notImpl
}

func (me *StubDB) FindExpiredPosts(space string) ([]*db.Post, error) {
return []*db.Post{}, notImpl
}

func (me *StubDB) FindUpdatedPostsForUser(userID string, space string) ([]*db.Post, error) {
return []*db.Post{}, notImpl
}

func (me *StubDB) Close() error {
return notImpl
}

func (me *StubDB) InsertVisit(view *db.AnalyticsVisits) error {
return notImpl
}

func (me *StubDB) VisitSummary(opts *db.SummaryOpts) (*db.SummaryVisits, error) {
return &db.SummaryVisits{}, notImpl
}

func (me *StubDB) FindUsers() ([]*db.User, error) {
return []*db.User{}, notImpl
}

func (me *StubDB) ReplaceTagsForPost(tags []string, postID string) error {
return notImpl
}

func (me *StubDB) ReplaceAliasesForPost(aliases []string, postID string) error {
return notImpl
}

func (me *StubDB) FindUserPostsByTag(page *db.Pager, tag, userID, space string) (*db.Paginate[*db.Post], error) {
return &db.Paginate[*db.Post]{}, notImpl
}

func (me *StubDB) FindPostsByTag(pager *db.Pager, tag, space string) (*db.Paginate[*db.Post], error) {
return &db.Paginate[*db.Post]{}, notImpl
}

func (me *StubDB) FindPopularTags(space string) ([]string, error) {
return []string{}, notImpl
}

func (me *StubDB) FindTagsForPost(postID string) ([]string, error) {
return []string{}, notImpl
}

func (me *StubDB) FindFeatureForUser(userID string, feature string) (*db.FeatureFlag, error) {
return nil, notImpl
}

func (me *StubDB) FindFeaturesForUser(userID string) ([]*db.FeatureFlag, error) {
return []*db.FeatureFlag{}, notImpl
}

func (me *StubDB) HasFeatureForUser(userID string, feature string) bool {
return false
}

func (me *StubDB) FindTotalSizeForUser(userID string) (int, error) {
return 0, notImpl
}

func (me *StubDB) InsertFeedItems(postID string, items []*db.FeedItem) error {
return notImpl
}

func (me *StubDB) FindFeedItemsByPostID(postID string) ([]*db.FeedItem, error) {
return []*db.FeedItem{}, notImpl
}

func (me *StubDB) InsertProject(userID, name, projectDir string) (string, error) {
return "", notImpl
}

func (me *StubDB) UpdateProject(userID, name string) error {
return notImpl
}

func (me *StubDB) UpdateProjectAcl(userID, name string, acl db.ProjectAcl) error {
return notImpl
}

func (me *StubDB) LinkToProject(userID, projectID, projectDir string, commit bool) error {
return notImpl
}

func (me *StubDB) RemoveProject(projectID string) error {
return notImpl
}

func (me *StubDB) FindProjectByName(userID, name string) (*db.Project, error) {
return &db.Project{}, notImpl
}

func (me *StubDB) FindProjectLinks(userID, name string) ([]*db.Project, error) {
return []*db.Project{}, notImpl
}

func (me *StubDB) FindProjectsByPrefix(userID, prefix string) ([]*db.Project, error) {
return []*db.Project{}, notImpl
}

func (me *StubDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
return []*db.Project{}, notImpl
}

func (me *StubDB) FindAllProjects(page *db.Pager, by string) (*db.Paginate[*db.Project], error) {
return &db.Paginate[*db.Project]{}, notImpl
}

func (me *StubDB) InsertToken(userID, name string) (string, error) {
return "", notImpl
}

func (me *StubDB) UpsertToken(userID, name string) (string, error) {
return "", notImpl
}

func (me *StubDB) FindTokenByName(userID, name string) (string, error) {
return "", notImpl
}

func (me *StubDB) RemoveToken(tokenID string) error {
return notImpl
}

func (me *StubDB) FindTokensForUser(userID string) ([]*db.Token, error) {
return []*db.Token{}, notImpl
}

func (me *StubDB) InsertFeature(userID, name string, expiresAt time.Time) (*db.FeatureFlag, error) {
return nil, notImpl
}

func (me *StubDB) RemoveFeature(userID string, name string) error {
return notImpl
}

func (me *StubDB) AddPicoPlusUser(username, paymentType, txId string) error {
return notImpl
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.3-0.20240912151726-82936c5ea257
github.com/neurosnap/go-exif-remove v0.0.0-20221010134343-50d1e3c35577
github.com/picosh/pobj v0.0.0-20241008013754-bbbfc341e2cf
github.com/picosh/pobj v0.0.0-20241016194248-c39198b2ff23
github.com/picosh/pubsub v0.0.0-20241008010300-a63fd95dc8ed
github.com/picosh/send v0.0.0-20241008013240-6fdbff00f848
github.com/picosh/tunkit v0.0.0-20240709033345-8315d4f3cd0e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1Gsh
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/picosh/go-rsync-receiver v0.0.0-20240709135253-1daf4b12a9fc h1:bvcsoOvaNHPquFnRkdraEo7+8t6bW7nWEhlALnwZPdI=
github.com/picosh/go-rsync-receiver v0.0.0-20240709135253-1daf4b12a9fc/go.mod h1:i0iR3W4GSm1PuvVxB9OH32E5jP+CYkVb2NQSe0JCtlo=
github.com/picosh/pobj v0.0.0-20241008013754-bbbfc341e2cf h1:Ul+LuTVXRimpIneOHez05k7VOV/lDVw37I18rceEplw=
github.com/picosh/pobj v0.0.0-20241008013754-bbbfc341e2cf/go.mod h1:cF+eAl4G1vU+WOD8cYCKaxokHo6MWmbR8J4/SJnvESg=
github.com/picosh/pobj v0.0.0-20241016194248-c39198b2ff23 h1:NEJ5a4UXeF0/X7xmYNzXcwLQID9DwgazlqkMMC5zZ3M=
github.com/picosh/pobj v0.0.0-20241016194248-c39198b2ff23/go.mod h1:cF+eAl4G1vU+WOD8cYCKaxokHo6MWmbR8J4/SJnvESg=
github.com/picosh/pubsub v0.0.0-20241008010300-a63fd95dc8ed h1:aBJeQoLvq/V3hX6bgWjuuTmGzgbPNYuuwaCWU4aSJcU=
github.com/picosh/pubsub v0.0.0-20241008010300-a63fd95dc8ed/go.mod h1:ajolgob5MxlHdp5HllF7u3rTlCgER4InqfP7M/xl6HQ=
github.com/picosh/send v0.0.0-20241008013240-6fdbff00f848 h1:VWbjNNOqpJ8AB3zdw+M5+XC/SINooWLGi6WCozKwt1o=
Expand Down
1 change: 1 addition & 0 deletions pgs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func (h *AssetHandler) handle(logger *slog.Logger, w http.ResponseWriter, r *htt

attempts = append(attempts, fp.Filepath)
mimeType := storage.GetMimeType(fp.Filepath)
logger = logger.With("filename", fp.Filepath)
var c io.ReadCloser
var err error
if strings.HasPrefix(mimeType, "image/") {
Expand Down
Loading

0 comments on commit 72b3683

Please sign in to comment.