Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam at luther/fix test oracle #40

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Config) SetSwaggerHandler(h http.Handler) {

// SetOTLPEndpoint is a helper to set the OTLP trace endpoint.
func (c *Config) SetOTLPEndpoint(endpoint string) {
if c == nil {
if c == nil || endpoint == "" {
return
}
c.TraceOpts = append(c.TraceOpts, opttrace.WithOTLPExporter(endpoint))
Expand Down Expand Up @@ -319,9 +319,6 @@ func (orc *Oracle) phylumHealthCheck(ctx context.Context) []*healthcheck.HealthC
break
}
}
if orc.getLastPhylumVersion() == "" {
orc.log(ctx).Warnf("missing phylum version")
}
return reports
}

Expand All @@ -340,6 +337,10 @@ func (orc *Oracle) GetHealthCheck(ctx context.Context, req *healthcheck.GetHealt
}
}
}
if orc.getLastPhylumVersion() == "" && !orc.cfg.EmulateCC {
orc.log(ctx).Warnf("missing phylum version")
}

reports = append(reports, &healthcheck.HealthCheckReport{
ServiceName: orc.cfg.ServiceName,
ServiceVersion: orc.cfg.Version,
Expand Down
1 change: 1 addition & 0 deletions oracle/oraclerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (orc *Oracle) grpcGateway(swaggerHandler http.Handler) (*runtime.ServeMux,
return jsonapi, middleware.Wrap(jsonapi)
}

// GrpcGatewayConfig configures the grpc gateway used by the oracle.
type GrpcGatewayConfig interface {
// RegisterServiceServer is required to be overidden by the implementation.
RegisterServiceServer(grpcServer *grpc.Server)
Expand Down
19 changes: 13 additions & 6 deletions oracle/oracletester.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package oracle
import (
"bytes"
"fmt"
"io"
"testing"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -65,23 +64,31 @@ func WithSnapshot(b []byte) TestOpt {
}

// NewTestOracle is used to create an oracle for testing.
func NewTestOracle(t *testing.T, testOpts ...TestOpt) (*Oracle, func()) {
func NewTestOracle(t *testing.T, cfg *Config, testOpts ...TestOpt) (*Oracle, func()) {
cfg.Verbose = testing.Verbose()
cfg.EmulateCC = true
cfg.Version = "test"

require.NoError(t, cfg.Valid())

testCfg := &testCfg{}
for _, opt := range testOpts {
opt(testCfg)
}
cfg := DefaultConfig()
cfg.Verbose = testing.Verbose()

logger := logrus.New()
logger.SetOutput(newTestWriter(t))
var r io.Reader

var r *bytes.Reader
if testCfg.snapshot != nil {
r = bytes.NewReader(testCfg.snapshot)
}

orcOpts := []option{
withLogBase(logger.WithFields(nil)),
withMockPhylumFrom("../../../phylum", r),
withMockPhylumFrom(cfg.PhylumPath, r),
}

server, err := newOracle(cfg, orcOpts...)
server.state = oracleStateTesting
if err != nil {
Expand Down