Documentation ¶
Overview ¶
Package testhelpers provides common testing helpers and utilities that are used across packages in this project. Only non-trivial helper logic used in multiple places in this library should be added here.
Index ¶
- func CheckErrorNDJSONFile(t *testing.T, dir string, wantErrors []ErrorNDJSONLine)
- func FHIRStoreServer(t *testing.T, expectedResources []FHIRStoreTestResource, ...) string
- func FHIRStoreServerBatch(t *testing.T, expectedFHIRResources [][]byte, expectedFullBatchSize int, ...) string
- func GCPLogServer() (*GRPCServer, *LoggingHandler, error)
- func NormalizeJSON(t *testing.T, jsonIn []byte) []byte
- func NormalizeJSONString(t *testing.T, jsonIn string) string
- func ReadAllFHIRJSON(t *testing.T, outputDir string, normalize bool) [][]byte
- func ReadAllGCSFHIRJSON(t *testing.T, gcsServer *GCSServer, normalize bool) [][]byte
- type ErrorNDJSONLine
- type FHIRStoreTestResource
- type GCSObjectEntry
- type GCSServer
- type GRPCServer
- type LoggingHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckErrorNDJSONFile ¶
func CheckErrorNDJSONFile(t *testing.T, dir string, wantErrors []ErrorNDJSONLine)
CheckErrorNDJSONFile is a helper to test that the contents of the error ndjson file written by fhirstore.Uploader are correct.
func FHIRStoreServer ¶
func FHIRStoreServer(t *testing.T, expectedResources []FHIRStoreTestResource, projectID, location, datasetID, fhirStoreID string) string
FHIRStoreServer creates a test FHIR store server that expects the provided expectedResources uploaded as single resources. If it receives valid upload requests that do not include elements from expectedResources, it will call t.Errorf with an error. If not all of the resources in expectedResources are uploaded by the end of the test errors are thrown. The test server's URL is returned by this function, and is auto-closed at the end of the test.
func FHIRStoreServerBatch ¶
func FHIRStoreServerBatch(t *testing.T, expectedFHIRResources [][]byte, expectedFullBatchSize int, projectID, location, datasetID, fhirStoreID string) string
FHIRStoreServerBatch sets up a test FHIR Store Server for batch executeBundle requests. It ensures proper executeBundle requests are sent, and that the bundles are in batch mode and contain the expectedFHIRResources. It is okay to upload the full set of expectedFHIRResources over multiple executeBundle batch calls to this server. At the end of the test, the teardown of this server checks and ensures that all expectedFHIRResources were uploaded at least once.
func GCPLogServer ¶
func GCPLogServer() (*GRPCServer, *LoggingHandler, error)
GCPLogServer creates an in-memory fake server implementing the GCP logging service and starts it. Call close on the server when done. GetLogsAfterClose can be used to verify logs were written.
func NormalizeJSON ¶
NormalizeJSON normalizes the input json bytes to look like how it would look as if marshaled from a json.Marshal. In particular, this may reorder some fields (e.g. json object keys are sorted alphabetically), but the json should be equivalent.
func NormalizeJSONString ¶
NormalizeJSONString normalizes the input json to look how it would look if marshaled from a json.Marshal.
func ReadAllFHIRJSON ¶
ReadAllFHIRJSON reads all ndjsons in the output directory, extracts out the FHIR json for each resource, and adds it to the output [][]byte. If normalize=true, then NormalizeJSON is applied to the json bytes before being added to the output.
func ReadAllGCSFHIRJSON ¶
ReadAllGCSFHIRJSON reads ALL files in the gcsServer, attempets to extract the FHIR json for each resource, and adds it to the output [][]byte. If normalize=true, then NormalizeJSON is applied to the json bytes before being added to the output.
Types ¶
type ErrorNDJSONLine ¶
ErrorNDJSONLine represents one line of an error NDJSON file produced by fhirstore.Uploader.
type FHIRStoreTestResource ¶
type FHIRStoreTestResource struct { ResourceID string ResourceTypeCode cpb.ResourceTypeCode_Value Data []byte }
FHIRStoreTestResource represents a test FHIR resource to be uploaded to FHIR store.
type GCSObjectEntry ¶
GCSObjectEntry holds the contents and content type of stored objects.
type GCSServer ¶
type GCSServer struct {
// contains filtered or unexported fields
}
GCSServer provides a minimal implementation of the GCS API for use in tests.
func NewGCSServer ¶
NewGCSServer creates a new GCS Server for use in tests.
func (*GCSServer) AddObject ¶
func (gs *GCSServer) AddObject(bucket, name string, obj GCSObjectEntry)
AddObject adds an object to be served by the GCS server.
func (*GCSServer) GetAllObjects ¶
func (gs *GCSServer) GetAllObjects() []GCSObjectEntry
GetAllObjects returns all objects uploaded to this test server across all buckets. Use this only if needed for your test, otherwise prefer GetObject.
func (*GCSServer) GetAllPaths ¶
GetAllPaths returns a slice representing the upload path of all items that have been uploaded to the test server in the form gs://bucket/path.
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
GRPCServer is an in-process gRPC server, listening on the local loopback interface. GRPCServers are for testing only and are not intended to be used in production code.
func (*GRPCServer) Addr ¶
func (s *GRPCServer) Addr() string
Addr returns the address of the server.
type LoggingHandler ¶
type LoggingHandler struct { logpb.LoggingServiceV2Server // contains filtered or unexported fields }
LoggingHandler implements the log rpc server and holds an in memory map of logs.
func (*LoggingHandler) GetLogsAfterClose ¶
func (h *LoggingHandler) GetLogsAfterClose() map[string][]*logpb.LogEntry
GetLogsAfterClose returns the in-memory map of written logs. It should be called after the Log Client is closed or flushed.
func (*LoggingHandler) WriteLogEntries ¶
func (h *LoggingHandler) WriteLogEntries(_ context.Context, req *logpb.WriteLogEntriesRequest) (*logpb.WriteLogEntriesResponse, error)
WriteLogEntries usually writes log entries to Cloud Logging. In this fake it saves the logs in an in-memory map. This function must be exported for the grpc server to work but should not be called directly in tests.