Skip to content

Commit c3f8ab0

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # app/cmd/server_test.go
2 parents fcbb521 + 8be7a79 commit c3f8ab0

File tree

1,596 files changed

+236053
-121858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,596 files changed

+236053
-121858
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: set up go 1.14
14+
- name: set up go 1.15
1515
uses: actions/setup-go@v1
1616
with:
1717
go-version: 1.15
@@ -20,7 +20,7 @@ jobs:
2020
- name: launch mongodb
2121
uses: wbari/start-mongoDB@v0.2
2222
with:
23-
mongoDBVersion: "4.0"
23+
mongoDBVersion: "4.2"
2424

2525
- name: checkout
2626
uses: actions/checkout@v2
@@ -42,8 +42,10 @@ jobs:
4242
4343
- name: run linters
4444
run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions ./...
45+
working-directory: app
4546
env:
4647
GO111MODULE: on
48+
GOFLAGS: "-mod=vendor"
4749

4850
- name: submit coverage
4951
run: $(go env GOPATH)/bin/goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ issues:
7272
- text: "at least one file in a package should have a package comment"
7373
linters:
7474
- stylecheck
75+
- text: "whyNoLint: include an explanation for nolint directive"
76+
linters:
77+
- gocritic
7578
exclude-use-default: false
7679

7780
service:

app/agent/demo_mode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package agent
33
import (
44
"context"
55
"fmt"
6-
"math/rand"
6+
"math/rand" //nolint:gosec
77
"time"
88

99
log "github.com/go-pkgz/lgr"
@@ -27,11 +27,11 @@ func (d *DemoEmitter) Logs(o docker.LogsOptions) error {
2727
var line string
2828
switch o.Container {
2929
case "nginx":
30-
line = nginxDemo[rand.Intn(len(nginxDemo)-1)]
30+
line = nginxDemo[rand.Intn(len(nginxDemo)-1)] //nolint:gosec
3131
case "rest":
32-
line = restDemo[rand.Intn(len(restDemo)-1)]
32+
line = restDemo[rand.Intn(len(restDemo)-1)] //nolint:gosec
3333
case "mongo":
34-
line = mongoDemo[rand.Intn(len(mongoDemo)-1)]
34+
line = mongoDemo[rand.Intn(len(mongoDemo)-1)] //nolint:gosec
3535

3636
}
3737

app/client/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type APIParams struct {
3939
// DisplayParams customizes how records will be showed
4040
type DisplayParams struct {
4141
ShowPid bool // include pid
42-
ShowTs bool // include time stamp as "2006-01-02 15:04:05.999999" in given TZ
42+
ShowTS bool // include time stamp as "2006-01-02 15:04:05.999999" in given TZ
4343
FollowMode bool // follow mode, like -f in grep
4444
TailMode bool // tail mode, like -t in grep
4545
ShowSyslog bool // show non-docker messages from syslog, off by default
@@ -133,8 +133,8 @@ func (c *CLI) makeOutLine(e core.LogEntry) (string, bool) {
133133
}
134134

135135
ts := ""
136-
if c.ShowTs {
137-
ts = fmt.Sprintf(" - %s", e.Ts.In(c.TimeZone).Format("2006-01-02 15:04:05.999999"))
136+
if c.ShowTS {
137+
ts = fmt.Sprintf(" - %s", e.TS.In(c.TimeZone).Format("2006-01-02 15:04:05.999999"))
138138
}
139139
line := fmt.Sprintf("%s:%s%s%s - %s\n", red(e.Host), green(e.Container), yellow(ts), yellow(pid), white(e.Msg))
140140
return line, true

app/client/cli_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestCliWithPidAndTS(t *testing.T) {
4242

4343
out := bytes.Buffer{}
4444

45-
c := NewCLI(APIParams{API: ts.URL + "/v1", Client: &http.Client{}}, DisplayParams{Out: &out, ShowPid: true, ShowTs: true})
45+
c := NewCLI(APIParams{API: ts.URL + "/v1", Client: &http.Client{}}, DisplayParams{Out: &out, ShowPid: true, ShowTS: true})
4646
_, err := c.Activate(context.Background(), core.Request{})
4747
require.NoError(t, err)
4848
exp := "h1:c1 - 2019-05-24 20:54:30 [0] - msg1\nh1:c2 - 2019-05-24 20:54:31 [0] - msg2\n" +
@@ -60,7 +60,7 @@ func TestCliWithCustomTZ(t *testing.T) {
6060

6161
tz, err := time.LoadLocation("America/New_York")
6262
require.NoError(t, err)
63-
c := NewCLI(APIParams{API: ts.URL + "/v1", Client: &http.Client{}}, DisplayParams{Out: &out, TimeZone: tz, ShowTs: true})
63+
c := NewCLI(APIParams{API: ts.URL + "/v1", Client: &http.Client{}}, DisplayParams{Out: &out, TimeZone: tz, ShowTS: true})
6464
_, err = c.Activate(context.Background(), core.Request{})
6565
require.NoError(t, err)
6666
exp := "h1:c1 - 2019-05-24 21:54:30 - msg1\nh1:c2 - 2019-05-24 21:54:31 - msg2\nh2:c1 - 2019-05-24 21:54:32 - msg3\n" +
@@ -101,7 +101,7 @@ func TestLastID(t *testing.T) {
101101
}
102102
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
103103
rec := core.LogEntry{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1",
104-
Msg: "msg1", Ts: ts.Add(0 * time.Second)}
104+
Msg: "msg1", TS: ts.Add(0 * time.Second)}
105105

106106
err := json.NewEncoder(w).Encode(&rec)
107107
require.NoError(t, err)
@@ -141,12 +141,12 @@ func TestCliFindFailedAndRestored(t *testing.T) {
141141
if r.URL.Path == "/v1/find" && r.Method == "POST" {
142142
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
143143
recs := []core.LogEntry{
144-
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", Ts: ts.Add(0 * time.Second)},
145-
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", Ts: ts.Add(1 * time.Second)},
146-
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", Ts: ts.Add(2 * time.Second)},
147-
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", Ts: ts.Add(3 * time.Second)},
148-
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", Ts: ts.Add(4 * time.Second)},
149-
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", Ts: ts.Add(5 * time.Second)},
144+
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", TS: ts.Add(0 * time.Second)},
145+
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", TS: ts.Add(1 * time.Second)},
146+
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", TS: ts.Add(2 * time.Second)},
147+
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", TS: ts.Add(3 * time.Second)},
148+
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", TS: ts.Add(4 * time.Second)},
149+
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", TS: ts.Add(5 * time.Second)},
150150
}
151151
err := json.NewEncoder(w).Encode(recs)
152152
require.NoError(t, err)
@@ -198,7 +198,7 @@ func TestCliFindFollow(t *testing.T) {
198198
{
199199
ID: fmt.Sprintf("5ce8718aef1d7346a5443a1%d", c),
200200
Host: "h1", Container: "c1", Msg: fmt.Sprintf("msg%d", c),
201-
Ts: ts.Add(time.Duration(c) * time.Second),
201+
TS: ts.Add(time.Duration(c) * time.Second),
202202
},
203203
}
204204
require.NoError(t, json.NewEncoder(w).Encode(recs))
@@ -237,7 +237,7 @@ func TestCliFindFollowWithDelay(t *testing.T) {
237237
{
238238
ID: fmt.Sprintf("5ce8718aef1d7346a5443a1%d", c),
239239
Host: "h1", Container: "c1", Msg: fmt.Sprintf("msg%d", c),
240-
Ts: ts.Add(time.Duration(c) * time.Second),
240+
TS: ts.Add(time.Duration(c) * time.Second),
241241
},
242242
}
243243
require.NoError(t, json.NewEncoder(w).Encode(recs))
@@ -269,7 +269,7 @@ func TestCliFindTail(t *testing.T) {
269269
if r.URL.Path == "/v1/last" && r.Method == "GET" {
270270
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
271271
rec := core.LogEntry{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1",
272-
Msg: "msg1", Ts: ts.Add(5 * time.Second)}
272+
Msg: "msg1", TS: ts.Add(5 * time.Second)}
273273
err := json.NewEncoder(w).Encode(&rec)
274274
require.NoError(t, err)
275275
}
@@ -286,7 +286,7 @@ func TestCliFindTail(t *testing.T) {
286286
require.Equal(t, "5ce8718aef1d7346a5443a1f", req.LastID)
287287
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
288288
recs := []core.LogEntry{{ID: "5ce8718aef1d7346a5443a12f", Host: "h1", Container: "c1",
289-
Msg: "msg1", Ts: ts.Add(15 * time.Second)}}
289+
Msg: "msg1", TS: ts.Add(15 * time.Second)}}
290290
require.NoError(t, json.NewEncoder(w).Encode(recs))
291291
}
292292
}))
@@ -349,12 +349,12 @@ func prepTestServer(t *testing.T) *httptest.Server {
349349

350350
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
351351
recs := []core.LogEntry{
352-
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", Ts: ts.Add(0 * time.Second)},
353-
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", Ts: ts.Add(1 * time.Second)},
354-
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", Ts: ts.Add(2 * time.Second)},
355-
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", Ts: ts.Add(3 * time.Second)},
356-
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", Ts: ts.Add(4 * time.Second)},
357-
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", Ts: ts.Add(5 * time.Second)},
352+
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", TS: ts.Add(0 * time.Second)},
353+
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", TS: ts.Add(1 * time.Second)},
354+
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", TS: ts.Add(2 * time.Second)},
355+
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", TS: ts.Add(3 * time.Second)},
356+
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", TS: ts.Add(4 * time.Second)},
357+
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", TS: ts.Add(5 * time.Second)},
358358
}
359359
err = json.NewEncoder(w).Encode(recs)
360360
require.NoError(t, err)
@@ -364,7 +364,7 @@ func prepTestServer(t *testing.T) *httptest.Server {
364364
if r.URL.Path == "/v1/last" && r.Method == "GET" {
365365
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
366366
rec := core.LogEntry{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1",
367-
Msg: "msg1", Ts: ts.Add(5 * time.Second)}
367+
Msg: "msg1", TS: ts.Add(5 * time.Second)}
368368
err := json.NewEncoder(w).Encode(&rec)
369369
require.NoError(t, err)
370370
}

app/cmd/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ClientOpts struct {
1717
Containers []string `short:"c" description:"show container(s) only"`
1818
Hosts []string `short:"h" description:"show host(s) only"`
1919
Excludes []string `short:"x" description:"exclude container(s)"`
20-
ShowTs bool `short:"m" description:"show syslog timestamp"`
20+
ShowTS bool `short:"m" description:"show syslog timestamp"`
2121
ShowPid bool `short:"p" description:"show pid"`
2222
ShowSyslog bool `short:"s" description:"show syslog messages"`
2323
FollowMode bool `short:"f" description:"follow mode"`
@@ -56,7 +56,7 @@ func (c ClientCmd) Run(ctx context.Context) error {
5656

5757
display := client.DisplayParams{
5858
ShowPid: c.ShowPid,
59-
ShowTs: c.ShowTs,
59+
ShowTS: c.ShowTS,
6060
FollowMode: c.FollowMode,
6161
TailMode: c.TailMode,
6262
ShowSyslog: c.ShowSyslog,

app/cmd/client_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestClient(t *testing.T) {
2525
c := ClientCmd{ClientOpts{
2626
API: ts.URL + "/v1",
2727
TimeZone: "America/New_York",
28-
ShowTs: true,
28+
ShowTS: true,
2929
}}
3030

3131
lgr.Out(ioutil.Discard)
@@ -67,12 +67,12 @@ func prepTestServer(t *testing.T) *httptest.Server {
6767

6868
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
6969
recs := []core.LogEntry{
70-
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", Ts: ts.Add(0 * time.Second)},
71-
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", Ts: ts.Add(1 * time.Second)},
72-
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", Ts: ts.Add(2 * time.Second)},
73-
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", Ts: ts.Add(3 * time.Second)},
74-
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", Ts: ts.Add(4 * time.Second)},
75-
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", Ts: ts.Add(5 * time.Second)},
70+
{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1", Msg: "msg1", TS: ts.Add(0 * time.Second)},
71+
{ID: "5ce8718aef1d7346a5443a2f", Host: "h1", Container: "c2", Msg: "msg2", TS: ts.Add(1 * time.Second)},
72+
{ID: "5ce8718aef1d7346a5443a3f", Host: "h2", Container: "c1", Msg: "msg3", TS: ts.Add(2 * time.Second)},
73+
{ID: "5ce8718aef1d7346a5443a4f", Host: "h1", Container: "c1", Msg: "msg4", TS: ts.Add(3 * time.Second)},
74+
{ID: "5ce8718aef1d7346a5443a5f", Host: "h1", Container: "c2", Msg: "msg5", TS: ts.Add(4 * time.Second)},
75+
{ID: "5ce8718aef1d7346a5443a6f", Host: "h2", Container: "c2", Msg: "msg6", TS: ts.Add(5 * time.Second)},
7676
}
7777
err = json.NewEncoder(w).Encode(recs)
7878
require.NoError(t, err)
@@ -82,7 +82,7 @@ func prepTestServer(t *testing.T) *httptest.Server {
8282
if r.URL.Path == "/v1/last" && r.Method == "GET" {
8383
ts := time.Date(2019, 5, 24, 20, 54, 30, 0, time.Local)
8484
rec := core.LogEntry{ID: "5ce8718aef1d7346a5443a1f", Host: "h1", Container: "c1",
85-
Msg: "msg1", Ts: ts.Add(5 * time.Second)}
85+
Msg: "msg1", TS: ts.Add(5 * time.Second)}
8686
err := json.NewEncoder(w).Encode(&rec)
8787
require.NoError(t, err)
8888
}

app/cmd/server.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99
"path"
1010
"time"
1111

12-
"github.com/globalsign/mgo"
13-
"gopkg.in/natefinch/lumberjack.v2"
1412
log "github.com/go-pkgz/lgr"
13+
"github.com/go-pkgz/mongo/v2"
14+
"github.com/pkg/errors"
15+
mdrv "go.mongodb.org/mongo-driver/mongo"
16+
"go.mongodb.org/mongo-driver/mongo/options"
17+
"gopkg.in/natefinch/lumberjack.v2"
1518

1619
"github.com/umputun/dkll/app/server"
1720
)
@@ -20,13 +23,8 @@ import (
2023
type ServerOpts struct {
2124
Port int `long:"api-port" env:"API_PORT" default:"8080" description:"rest server port"`
2225
SyslogPort int `long:"syslog-port" env:"SYSLOG_PORT" default:"5514" description:"syslog server port"`
23-
Mongo []string `long:"mongo" env:"MONGO" required:"true" env-delim:"," description:"mongo host:port"`
24-
MongoUser string `long:"mongo-user" env:"MONGO_USER" default:"admin" description:"mongo user for auth"`
25-
MongoPasswd string `long:"mongo-passwd" env:"MONGO_PASSWD" default:"" description:"mongo password"`
26-
MongoDelay time.Duration `long:"mongo-delay" env:"MONGO_DELAY" default:"0s" description:"mongo initial delay"`
26+
MongoURL string `long:"mongo" env:"MONGO" required:"true" env-delim:"," description:"mongo host:port"`
2727
MongoTimeout time.Duration `long:"mongo-timeout" env:"MONGO_TIMEOUT" default:"5s" description:"mongo timeout"`
28-
MongoDB string `long:"mongo-db" env:"MONGO_DB" default:"dkll" description:"mongo database name"`
29-
MongoColl string `long:"mongo-coll" env:"MONGO_COLL" default:"msgs" description:"mongo collection name"`
3028
MongoMaxSize int `long:"mongo-size" env:"MONGO_SIZE" default:"10000000000" description:"max collection size"`
3129
MongoMaxDocs int `long:"mongo-docs" env:"MONGO_DOCS" default:"50000000" description:"max docs in collection"`
3230
FileBackupLocation string `long:"backup" default:"" env:"BACK_LOG" description:"backup log files location"`
@@ -61,22 +59,13 @@ func (s ServerCmd) Run(ctx context.Context) error {
6159
return err
6260
}
6361

64-
dial := mgo.DialInfo{
65-
Addrs: s.Mongo,
66-
AppName: "dkll",
67-
Timeout: s.MongoTimeout,
68-
Database: "admin",
69-
}
70-
71-
if s.MongoPasswd != "" {
72-
dial.Username = s.MongoUser
73-
dial.Password = s.MongoPasswd
74-
log.Printf("[INFO] mongo auth enforced with user %s", s.MongoUser)
62+
mclient, ex, err := makeMongoClient(s.MongoURL, s.MongoTimeout)
63+
if err != nil {
64+
return errors.Wrap(err, "can't make mongo client")
7565
}
76-
77-
mgParams := server.MongoParams{DBName: s.MongoDB, Collection: s.MongoColl, Delay: s.MongoDelay,
66+
mgParams := server.MongoParams{DBName: ex["db"].(string), Collection: ex["collection"].(string),
7867
MaxDocs: s.MongoMaxDocs, MaxCollectionSize: s.MongoMaxSize}
79-
mg, err := server.NewMongo(dial, mgParams)
68+
mg, err := server.NewMongo(mclient, mgParams)
8069
if err != nil {
8170
return err
8271
}
@@ -105,6 +94,23 @@ func (s ServerCmd) Run(ctx context.Context) error {
10594
return nil
10695
}
10796

97+
func makeMongoClient(mongoURL string, timeout time.Duration) (*mdrv.Client, map[string]interface{}, error) {
98+
log.Printf("[DEBUG] make mongo client for %q", mongoURL)
99+
if mongoURL == "" {
100+
return nil, nil, errors.New("no mongo URL provided")
101+
}
102+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
103+
defer cancel()
104+
105+
client, ex, err := mongo.Connect(ctx, options.Client().
106+
SetAppName("dkll-server").SetConnectTimeout(timeout), mongoURL, "db", "collection")
107+
108+
if err != nil {
109+
return nil, nil, errors.Wrapf(err, "can't connect to mongo %s", mongoURL)
110+
}
111+
return client, ex, nil
112+
}
113+
108114
func (s ServerCmd) makeWriters() (wrf server.WritersFactory, mergeLogWriter io.Writer, err error) {
109115

110116
// default loggers empty

app/cmd/server_test.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"testing"
1414
"time"
1515

16-
"github.com/globalsign/mgo"
1716
log "github.com/go-pkgz/lgr"
18-
"github.com/go-pkgz/mongo"
17+
"github.com/go-pkgz/mongo/v2"
1918
"github.com/stretchr/testify/assert"
2019
"github.com/stretchr/testify/require"
2120

@@ -24,20 +23,21 @@ import (
2423

2524
func TestServer(t *testing.T) {
2625
log.Printf("start server test")
27-
mg, err := mongo.NewServer(mgo.DialInfo{Addrs: []string{"127.0.0.1:27017"}, Database: "test"}, mongo.ServerParams{})
28-
require.NoError(t, err)
29-
mgConn := mongo.NewConnection(mg, "test", "msgs")
30-
cleanupTestAssets(t, "/tmp/dkll-test", mgConn)
31-
defer cleanupTestAssets(t, "/tmp/dkll-test", mgConn)
26+
27+
_, coll, teardown := mongo.MakeTestConnection(t)
28+
defer teardown()
29+
// m, err := server.NewMongo(mg, server.MongoParams{DBName: "test", Collection: coll.Name()})
30+
// require.NoError(t, err)
31+
32+
os.RemoveAll("/tmp/dkll-test")
3233

3334
opts := ServerOpts{
3435
Port: 8080,
3536
SyslogPort: 15514,
36-
Mongo: []string{"127.0.0.1:27017"},
37-
MongoDB: "test",
38-
MongoColl: "msgs",
37+
MongoURL: getMongoURL(t) + "?db=test&collection=" + coll.Name(),
3938
EnableMerged: true,
4039
FileBackupLocation: "/tmp/dkll-test",
40+
MongoMaxDocs: 100,
4141
}
4242
s := ServerCmd{ServerOpts: opts}
4343

@@ -114,9 +114,14 @@ func TestServer(t *testing.T) {
114114
log.Printf("start wait completed")
115115
}
116116

117-
func cleanupTestAssets(_ *testing.T, loc string, conn *mongo.Connection) {
118-
_ = os.RemoveAll(loc)
119-
_ = conn.WithCollection(func(coll *mgo.Collection) error {
120-
return coll.DropCollection()
121-
})
117+
func getMongoURL(t *testing.T) string {
118+
mongoURL := os.Getenv("MONGO_TEST")
119+
if mongoURL == "" {
120+
mongoURL = "mongodb://mongo:27017"
121+
t.Logf("no MONGO_TEST in env, defaulted to %s", mongoURL)
122+
}
123+
if mongoURL == "skip" {
124+
t.Skip("skip mongo test")
125+
}
126+
return mongoURL
122127
}

0 commit comments

Comments
 (0)