Skip to content

Commit 9077875

Browse files
test: e2e-test (#104)
1 parent 136b628 commit 9077875

14 files changed

+763
-1416
lines changed

.github/workflows/test.yml

+9
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ jobs:
1111
go-version: "1.21"
1212
- name: run tests
1313
run: make test
14+
e2e-test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: "1.21"
21+
- name: run e2e-tests
22+
run: make e2e-test

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ test: tidy
4848
@echo "Running unit tests..."
4949
@go test ./... -coverprofile=${COVERAGE_DIR}/coverage.out
5050

51+
e2e-test: tidy
52+
@echo "Running e2e-test tests..."
53+
@go test -v ./test/e2e_test/...
54+
5155
test-coverage: test
5256
@echo "Generating coverage report..."
5357
@go tool cover -html=${COVERAGE_DIR}/coverage.out

cli/config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ const configFlag = "config"
2323
// Config contains the application configuration.
2424
type Config struct {
2525
Log logger.LogConfig `mapstructure:"log"`
26-
Syncer syncerConf `mapstructure:"syncer"`
27-
Service serveConfig `mapstructure:"service"`
26+
Syncer SyncerConf `mapstructure:"syncer"`
27+
Service ServeConfig `mapstructure:"service"`
2828
PGConnStr string `mapstructure:"pg_conn_str" default:"postgres://postgres@localhost:5432/entropy?sslmode=disable"`
2929
Telemetry telemetry.Config `mapstructure:"telemetry"`
3030
}
3131

32-
type syncerConf struct {
32+
type SyncerConf struct {
3333
SyncInterval time.Duration `mapstructure:"sync_interval" default:"1s"`
3434
RefreshInterval time.Duration `mapstructure:"refresh_interval" default:"3s"`
3535
ExtendLockBy time.Duration `mapstructure:"extend_lock_by" default:"5s"`
3636
SyncBackoffInterval time.Duration `mapstructure:"sync_backoff_interval" default:"5s"`
3737
MaxRetries int `mapstructure:"max_retries" default:"5"`
3838
}
3939

40-
type serveConfig struct {
40+
type ServeConfig struct {
4141
Host string `mapstructure:"host" default:""`
4242
Port int `mapstructure:"port" default:"8080"`
4343

@@ -50,9 +50,9 @@ type clientConfig struct {
5050
Host string `mapstructure:"host" default:"localhost:8080"`
5151
}
5252

53-
func (serveCfg serveConfig) httpAddr() string { return serveCfg.HTTPAddr }
53+
func (serveCfg ServeConfig) httpAddr() string { return serveCfg.HTTPAddr }
5454

55-
func (serveCfg serveConfig) grpcAddr() string {
55+
func (serveCfg ServeConfig) grpcAddr() string {
5656
return fmt.Sprintf("%s:%d", serveCfg.Host, serveCfg.Port)
5757
}
5858

cli/serve.go

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"context"
45
"time"
56

67
"github.com/newrelic/go-agent/v3/newrelic"
@@ -39,42 +40,46 @@ func cmdServe() *cobra.Command {
3940
return err
4041
}
4142

42-
err = logger.Setup(&cfg.Log)
43-
if err != nil {
44-
return err
45-
}
43+
return StartServer(cmd.Context(), cfg, migrate, spawnWorker)
44+
})
4645

47-
telemetry.Init(cmd.Context(), cfg.Telemetry)
48-
nrApp, err := newrelic.NewApplication(
49-
newrelic.ConfigAppName(cfg.Telemetry.ServiceName),
50-
newrelic.ConfigLicense(cfg.Telemetry.NewRelicAPIKey),
51-
)
46+
return cmd
47+
}
48+
49+
func StartServer(ctx context.Context, cfg Config, migrate, spawnWorker bool) error {
50+
err := logger.Setup(&cfg.Log)
51+
if err != nil {
52+
return err
53+
}
5254

53-
store := setupStorage(cfg.PGConnStr, cfg.Syncer, cfg.Service)
54-
moduleService := module.NewService(setupRegistry(), store)
55-
resourceService := core.New(store, moduleService, time.Now, cfg.Syncer.SyncBackoffInterval, cfg.Syncer.MaxRetries)
55+
telemetry.Init(ctx, cfg.Telemetry)
56+
nrApp, err := newrelic.NewApplication(
57+
newrelic.ConfigAppName(cfg.Telemetry.ServiceName),
58+
newrelic.ConfigLicense(cfg.Telemetry.NewRelicAPIKey),
59+
)
5660

57-
if migrate {
58-
if migrateErr := runMigrations(cmd.Context(), cfg); migrateErr != nil {
59-
return migrateErr
60-
}
61-
}
61+
store := setupStorage(cfg.PGConnStr, cfg.Syncer, cfg.Service)
62+
moduleService := module.NewService(setupRegistry(), store)
63+
resourceService := core.New(store, moduleService, time.Now, cfg.Syncer.SyncBackoffInterval, cfg.Syncer.MaxRetries)
6264

63-
if spawnWorker {
64-
go func() {
65-
if runErr := resourceService.RunSyncer(cmd.Context(), cfg.Syncer.SyncInterval); runErr != nil {
66-
zap.L().Error("syncer exited with error", zap.Error(err))
67-
}
68-
}()
65+
if migrate {
66+
if migrateErr := runMigrations(ctx, cfg); migrateErr != nil {
67+
return migrateErr
6968
}
69+
}
7070

71-
return entropyserver.Serve(cmd.Context(),
72-
cfg.Service.httpAddr(), cfg.Service.grpcAddr(),
73-
nrApp, resourceService, moduleService,
74-
)
75-
})
71+
if spawnWorker {
72+
go func() {
73+
if runErr := resourceService.RunSyncer(ctx, cfg.Syncer.SyncInterval); runErr != nil {
74+
zap.L().Error("syncer exited with error", zap.Error(err))
75+
}
76+
}()
77+
}
7678

77-
return cmd
79+
return entropyserver.Serve(ctx,
80+
cfg.Service.httpAddr(), cfg.Service.grpcAddr(),
81+
nrApp, resourceService, moduleService,
82+
)
7883
}
7984

8085
func setupRegistry() module.Registry {
@@ -96,7 +101,7 @@ func setupRegistry() module.Registry {
96101
return registry
97102
}
98103

99-
func setupStorage(pgConStr string, syncCfg syncerConf, serveCfg serveConfig) *postgres.Store {
104+
func setupStorage(pgConStr string, syncCfg SyncerConf, serveCfg ServeConfig) *postgres.Store {
100105
store, err := postgres.Open(pgConStr, syncCfg.RefreshInterval, syncCfg.ExtendLockBy, serveCfg.PaginationSizeDefault, serveCfg.PaginationPageDefault)
101106
if err != nil {
102107
zap.L().Fatal("failed to connect to Postgres database",

go.mod

+43-22
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ require (
99
github.com/Masterminds/squirrel v1.5.4
1010
github.com/ghodss/yaml v1.0.0
1111
github.com/go-playground/validator/v10 v10.15.4
12-
github.com/google/go-cmp v0.5.9
12+
github.com/google/go-cmp v0.6.0
1313
github.com/gorilla/mux v1.8.0
14-
github.com/goto/salt v0.3.3
14+
github.com/goto/salt v0.3.7
1515
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
1616
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
1717
github.com/jmoiron/sqlx v1.3.5
@@ -24,20 +24,37 @@ require (
2424
github.com/newrelic/newrelic-opencensus-exporter-go v0.4.0
2525
github.com/rs/xid v1.5.0
2626
github.com/spf13/cobra v1.7.0
27-
github.com/stretchr/testify v1.8.4
27+
github.com/stretchr/testify v1.9.0
2828
github.com/xeipuuv/gojsonschema v1.2.0
2929
go.opencensus.io v0.24.0
3030
go.uber.org/zap v1.26.0
3131
google.golang.org/api v0.141.0
32-
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
33-
google.golang.org/grpc v1.58.1
34-
google.golang.org/protobuf v1.31.0
32+
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97
33+
google.golang.org/grpc v1.60.1
34+
google.golang.org/protobuf v1.32.0
3535
gopkg.in/yaml.v2 v2.4.0
3636
gotest.tools v2.2.0+incompatible
3737
helm.sh/helm/v3 v3.12.3
3838
k8s.io/api v0.28.2
3939
k8s.io/apimachinery v0.28.2
4040
k8s.io/client-go v0.28.2
41+
sigs.k8s.io/kind v0.23.0
42+
)
43+
44+
require (
45+
github.com/Microsoft/go-winio v0.6.1 // indirect
46+
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
47+
github.com/authzed/authzed-go v0.7.0 // indirect
48+
github.com/authzed/grpcutil v0.0.0-20230908193239-4286bb1d6403 // indirect
49+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
50+
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
51+
github.com/containerd/continuity v0.4.2 // indirect
52+
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
53+
github.com/jzelinskie/stringz v0.0.0-20210414224931-d6a8ce844a70 // indirect
54+
github.com/opencontainers/runc v1.1.5 // indirect
55+
github.com/ory/dockertest/v3 v3.9.1
56+
golang.org/x/mod v0.11.0 // indirect
57+
golang.org/x/tools v0.10.0 // indirect
4158
)
4259

4360
require (
@@ -72,7 +89,7 @@ require (
7289
github.com/fsnotify/fsnotify v1.6.0 // indirect
7390
github.com/go-errors/errors v1.5.0 // indirect
7491
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
75-
github.com/go-logr/logr v1.2.4 // indirect
92+
github.com/go-logr/logr v1.4.1 // indirect
7693
github.com/go-openapi/jsonpointer v0.20.0 // indirect
7794
github.com/go-openapi/jsonreference v0.20.2 // indirect
7895
github.com/go-openapi/swag v0.22.4 // indirect
@@ -127,8 +144,8 @@ require (
127144
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
128145
github.com/pkg/errors v0.9.1 // indirect
129146
github.com/pmezard/go-difflib v1.0.0 // indirect
130-
github.com/prometheus/client_golang v1.16.0 // indirect
131-
github.com/prometheus/client_model v0.4.0 // indirect
147+
github.com/prometheus/client_golang v1.17.0 // indirect
148+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
132149
github.com/prometheus/common v0.44.0 // indirect
133150
github.com/prometheus/procfs v0.11.1 // indirect
134151
github.com/rivo/uniseg v0.4.4 // indirect
@@ -142,7 +159,7 @@ require (
142159
github.com/spf13/jwalterweatherman v1.1.0 // indirect
143160
github.com/spf13/pflag v1.0.5 // indirect
144161
github.com/spf13/viper v1.16.0 // indirect
145-
github.com/stretchr/objx v0.5.0 // indirect
162+
github.com/stretchr/objx v0.5.2 // indirect
146163
github.com/subosito/gotenv v1.6.0 // indirect
147164
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
148165
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
@@ -151,13 +168,13 @@ require (
151168
github.com/yuin/goldmark-emoji v1.0.2 // indirect
152169
go.starlark.net v0.0.0-20230912135651-745481cf39ed // indirect
153170
go.uber.org/multierr v1.11.0 // indirect
154-
golang.org/x/crypto v0.13.0 // indirect
155-
golang.org/x/net v0.15.0 // indirect
156-
golang.org/x/oauth2 v0.12.0
157-
golang.org/x/sync v0.3.0 // indirect
158-
golang.org/x/sys v0.12.0 // indirect
159-
golang.org/x/term v0.12.0 // indirect
160-
golang.org/x/text v0.13.0 // indirect
171+
golang.org/x/crypto v0.20.0 // indirect
172+
golang.org/x/net v0.21.0 // indirect
173+
golang.org/x/oauth2 v0.13.0
174+
golang.org/x/sync v0.4.0 // indirect
175+
golang.org/x/sys v0.20.0 // indirect
176+
golang.org/x/term v0.17.0 // indirect
177+
golang.org/x/text v0.14.0 // indirect
161178
golang.org/x/time v0.3.0 // indirect
162179
google.golang.org/appengine v1.6.8 // indirect
163180
gopkg.in/inf.v0 v0.9.1 // indirect
@@ -184,11 +201,13 @@ require (
184201
cloud.google.com/go/compute/metadata v0.2.3 // indirect
185202
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
186203
github.com/Microsoft/hcsshim v0.11.0 // indirect
204+
github.com/alessio/shellescape v1.4.1 // indirect
187205
github.com/andybalholm/brotli v1.0.5 // indirect
188206
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
189207
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
190208
github.com/cli/safeexec v1.0.1 // indirect
191209
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
210+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
192211
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
193212
github.com/go-kit/log v0.2.1 // indirect
194213
github.com/go-logfmt/logfmt v0.6.0 // indirect
@@ -198,20 +217,22 @@ require (
198217
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
199218
github.com/google/gnostic-models v0.6.8 // indirect
200219
github.com/google/s2a-go v0.1.7 // indirect
220+
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
201221
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
202222
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
203223
github.com/hashicorp/errwrap v1.1.0 // indirect
204224
github.com/hashicorp/go-multierror v1.1.1 // indirect
205225
github.com/leodido/go-urn v1.2.4 // indirect
206226
github.com/newrelic/csec-go-agent v0.4.0 // indirect
207227
github.com/newrelic/newrelic-telemetry-sdk-go v0.8.1 // indirect
228+
github.com/pelletier/go-toml v1.9.5 // indirect
208229
github.com/prometheus/statsd_exporter v0.24.0 // indirect
209230
github.com/valyala/bytebufferpool v1.0.0 // indirect
210231
github.com/valyala/fasthttp v1.50.0 // indirect
211-
go.opentelemetry.io/otel v1.18.0 // indirect
212-
go.opentelemetry.io/otel/metric v1.18.0 // indirect
213-
go.opentelemetry.io/otel/trace v1.18.0 // indirect
232+
go.opentelemetry.io/otel v1.27.0 // indirect
233+
go.opentelemetry.io/otel/metric v1.27.0 // indirect
234+
go.opentelemetry.io/otel/trace v1.27.0 // indirect
214235
golang.org/x/arch v0.5.0 // indirect
215-
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
216-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
236+
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect
237+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
217238
)

0 commit comments

Comments
 (0)