+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ffec91b
test: integrates keploy and adds recorded testcases for test coverage
re-Tick Jan 4, 2023
9ad4d8a
fix: updates the github action to run tests
re-Tick Jan 4, 2023
a2dc134
ci: adds installation cmd to run keploy-tests
re-Tick Jan 4, 2023
25a3a33
ci: adds build cmd for installation in keploy-tests
re-Tick Jan 4, 2023
7007e43
ci: runs keploy server in background during installation
re-Tick Jan 4, 2023
97b6283
fix: run build cmd instead of dist in github actions
re-Tick Jan 4, 2023
5db1d31
ci: removes --install cmd
re-Tick Jan 4, 2023
e39fe35
ci: installs keploy binary for testing
re-Tick Jan 5, 2023
9bdc1f9
style: removes redundant comments from github actions
re-Tick Jan 5, 2023
cc939f2
ci: adds new config before server boot in ci
re-Tick Jan 5, 2023
8fca062
ci: prints the config
re-Tick Jan 5, 2023
fe79a3a
ci: copies config.toml.sample into config.toml
re-Tick Jan 5, 2023
83b87f7
ci: removes env variable from test job
re-Tick Jan 5, 2023
0f6172f
test: merges master and updates recorded testcases
re-Tick Jan 9, 2023
8c54142
fix: updates go-sdk to latest version in go.mod
re-Tick Jan 9, 2023
245fcae
refactor: removes redudant keploy-tests
re-Tick Jan 9, 2023
0a58064
Merge branch 'master' into integrate-keploy
re-Tick Jan 9, 2023
3fcdb70
test: removes duplicate keploy yaml testcases
re-Tick Jan 10, 2023
54f5d27
test: records a keploy testcases call to increase test coverage
re-Tick Jan 10, 2023
03023c1
test: adds keploy-tests to increase coverage
re-Tick Jan 11, 2023
e2264cd
chore: uodates the comments in makefile
re-Tick Jan 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 29 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go

on:
pull_request:
branches: [ master ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Install-Keploy
run: |
cat config.toml.sample > config.toml

- name: Test
run: |
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/keploy /usr/local/bin && keploy &
make test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ frontend/build/
config.toml
node_modules
listmonk
dist/*
dist/*
coverage.tmp.txt
coverage.txt
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ $(BIN): $(shell find . -type f -name "*.go")
# Run the backend in dev mode. The frontend assets in dev mode are loaded from disk from frontend/dist.
.PHONY: run
run:
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go
./listmonk

# Build the JS frontend into frontend/dist.
$(FRONTEND_DIST): $(FRONTEND_DEPS)
Expand All @@ -62,7 +63,13 @@ run-frontend:
# Run Go tests.
.PHONY: test
test:
go test ./...
# go test ./...
mkdir uploads
CGO_ENABLED=0 export KEPLOY_MODE="test" && go test -coverpkg=./... -coverprofile=coverage.tmp.txt -covermode=atomic ./... -buildString '${BUILDSTR}' -versionString ${VERSION}
# the files with inmemory state are excluded. Since the state are not mocked therefore, testrun fails.
cat coverage.tmp.txt | grep -v -e "cmd/import.go" -e "cmd/tx.go" | grep -v -e "migrations" > coverage.txt
go tool cover -func coverage.txt
rm -r uploads

# Bundle all static assets including the JS frontend into the ./listmonk binary
# using stuffbin (installed with make deps).
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func handleGetDashboardCharts(c echo.Context) error {
app = c.Get("app").(*App)
)

out, err := app.core.GetDashboardCharts()
out, err := app.core.GetDashboardCharts(c.Request().Context())
if err != nil {
return err
}
Expand All @@ -76,7 +76,7 @@ func handleGetDashboardCounts(c echo.Context) error {
app = c.Get("app").(*App)
)

out, err := app.core.GetDashboardCounts()
out, err := app.core.GetDashboardCounts(c.Request().Context())
if err != nil {
return err
}
Expand Down
21 changes: 11 additions & 10 deletions cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"html/template"
"net/http"
Expand All @@ -28,7 +29,7 @@ func handleGetCampaignArchives(c echo.Context) error {
pg = app.paginator.NewFromURL(c.Request().URL.Query())
)

camps, total, err := getCampaignArchives(pg.Offset, pg.Limit, app)
camps, total, err := getCampaignArchives(c.Request().Context(), pg.Offset, pg.Limit, app)
if err != nil {
return err
}
Expand All @@ -55,7 +56,7 @@ func handleGetCampaignArchivesFeed(c echo.Context) error {
pg = app.paginator.NewFromURL(c.Request().URL.Query())
)

camps, _, err := getCampaignArchives(pg.Offset, pg.Limit, app)
camps, _, err := getCampaignArchives(c.Request().Context(), pg.Offset, pg.Limit, app)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,7 +92,7 @@ func handleCampaignArchivesPage(c echo.Context) error {
pg = app.paginator.NewFromURL(c.Request().URL.Query())
)

out, total, err := getCampaignArchives(pg.Offset, pg.Limit, app)
out, total, err := getCampaignArchives(c.Request().Context(), pg.Offset, pg.Limit, app)
if err != nil {
return err
}
Expand All @@ -114,7 +115,7 @@ func handleCampaignArchivePage(c echo.Context) error {
uuid = c.Param("uuid")
)

pubCamp, err := app.core.GetArchivedCampaign(0, uuid)
pubCamp, err := app.core.GetArchivedCampaign(c.Request().Context(), 0, uuid)
if err != nil || pubCamp.Type != models.CampaignTypeRegular {
notFound := false
if er, ok := err.(*echo.HTTPError); ok {
Expand All @@ -134,7 +135,7 @@ func handleCampaignArchivePage(c echo.Context) error {
makeMsgTpl(app.i18n.T("public.errorTitle"), "", app.i18n.Ts("public.errorFetchingCampaign")))
}

out, err := compileArchiveCampaigns([]models.Campaign{pubCamp}, app)
out, err := compileArchiveCampaigns(c.Request().Context(), []models.Campaign{pubCamp}, app)
if err != nil {
return c.Render(http.StatusInternalServerError, tplMessage,
makeMsgTpl(app.i18n.T("public.errorTitle"), "", app.i18n.Ts("public.errorFetchingCampaign")))
Expand All @@ -152,13 +153,13 @@ func handleCampaignArchivePage(c echo.Context) error {
return c.HTML(http.StatusOK, string(msg.Body()))
}

func getCampaignArchives(offset, limit int, app *App) ([]campArchive, int, error) {
pubCamps, total, err := app.core.GetArchivedCampaigns(offset, limit)
func getCampaignArchives(ctx context.Context, offset, limit int, app *App) ([]campArchive, int, error) {
pubCamps, total, err := app.core.GetArchivedCampaigns(ctx, offset, limit)
if err != nil {
return []campArchive{}, total, echo.NewHTTPError(http.StatusInternalServerError, app.i18n.T("public.errorFetchingCampaign"))
}

msgs, err := compileArchiveCampaigns(pubCamps, app)
msgs, err := compileArchiveCampaigns(ctx, pubCamps, app)
if err != nil {
return []campArchive{}, total, err
}
Expand All @@ -178,15 +179,15 @@ func getCampaignArchives(offset, limit int, app *App) ([]campArchive, int, error
return out, total, nil
}

func compileArchiveCampaigns(camps []models.Campaign, app *App) ([]manager.CampaignMessage, error) {
func compileArchiveCampaigns(ctx context.Context, camps []models.Campaign, app *App) ([]manager.CampaignMessage, error) {
var (
b = bytes.Buffer{}
)

out := make([]manager.CampaignMessage, 0, len(camps))
for _, c := range camps {
camp := c
if err := camp.CompileTemplate(app.manager.TemplateFuncs(&camp)); err != nil {
if err := camp.CompileTemplate(app.manager.TemplateFuncs(ctx, &camp)); err != nil {
app.log.Printf("error compiling template: %v", err)
return nil, echo.NewHTTPError(http.StatusInternalServerError, app.i18n.T("public.errorFetchingCampaign"))
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/bounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io/ioutil"
"net/http"
"strconv"
"time"

"github.com/keploy/go-sdk/integrations/kclock"
"github.com/knadh/listmonk/models"
"github.com/labstack/echo/v4"
)
Expand All @@ -26,14 +26,14 @@ func handleGetBounces(c echo.Context) error {

// Fetch one bounce.
if id > 0 {
out, err := app.core.GetBounce(id)
out, err := app.core.GetBounce(c.Request().Context(), id)
if err != nil {
return err
}
return c.JSON(http.StatusOK, okResp{out})
}

res, total, err := app.core.QueryBounces(campID, 0, source, orderBy, order, pg.Offset, pg.Limit)
res, total, err := app.core.QueryBounces(c.Request().Context(), campID, 0, source, orderBy, order, pg.Offset, pg.Limit)
if err != nil {
return err
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func handleGetSubscriberBounces(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID"))
}

out, _, err := app.core.QueryBounces(0, subID, "", "", "", 0, 1000)
out, _, err := app.core.QueryBounces(c.Request().Context(), 0, subID, "", "", "", 0, 1000)
if err != nil {
return err
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func handleDeleteBounces(c echo.Context) error {
IDs = i
}

if err := app.core.DeleteBounces(IDs); err != nil {
if err := app.core.DeleteBounces(c.Request().Context(), IDs); err != nil {
return err
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func handleBounceWebhook(c echo.Context) error {
}

if b.CreatedAt.Year() == 0 {
b.CreatedAt = time.Now()
b.CreatedAt = kclock.Now(c.Request().Context())
}

bounces = append(bounces, b)
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载