Skip to content

Commit

Permalink
Correctly skip R5 in reference_test.go.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627790074
  • Loading branch information
suyashkumar authored and copybara-github committed Apr 25, 2024
1 parent db996d8 commit 49d23bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions go/jsonformat/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package jsonformat

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -27,29 +26,31 @@ import (
d3pb "github.com/google/fhir/go/proto/google/fhir/proto/stu3/datatypes_go_proto"
)

func referenceProto(ver apb.FhirVersion) proto.Message {
func referenceProto(t *testing.T, ver apb.FhirVersion) proto.Message {
switch ver {
case apb.FhirVersion_STU3:
return &d3pb.Reference{}
case apb.FhirVersion_R4:
return &d4pb.Reference{}
}
panic(fmt.Sprintf("unexpected version: %s", ver))
t.Fatalf("unsupported version: %s", ver)
return nil
}

func TestAllReferenceTypes(t *testing.T) {
var versions []apb.FhirVersion
versionsToSkip := []apb.FhirVersion{
apb.FhirVersion_FHIR_VERSION_UNKNOWN,
apb.FhirVersion_R4B, // TODO(b/265289586): Testing support for r4b
apb.FhirVersion_R5,
}

for _, v := range apb.FhirVersion_value {
ver := apb.FhirVersion(v)
// TODO(b/265289586): Testing support for r4b
if ver != apb.FhirVersion_FHIR_VERSION_UNKNOWN && ver != apb.FhirVersion_DSTU2 && ver != apb.FhirVersion_R4B {
versions = append(versions, ver)
if contains(versionsToSkip, ver) {
t.Skipf("Skipping testing version: %s", ver.String())
}
}

for _, ver := range versions {
t.Run(ver.String(), func(t *testing.T) {
ref := referenceProto(ver)
ref := referenceProto(t, ver)
if err := NormalizeReference(ref); err != nil {
t.Fatalf("unsupported version: %s", ver)
}
Expand All @@ -60,6 +61,15 @@ func TestAllReferenceTypes(t *testing.T) {
}
}

func contains(sl []apb.FhirVersion, v apb.FhirVersion) bool {
for _, e := range sl {
if e == v {
return true
}
}
return false
}

func TestNormalizeDenormalizeReference(t *testing.T) {
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion go/jsonformat/unmarshaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ func TestUnmarshal_ExtendedValidation_Errors(t *testing.T) {
}]
}`,
&jsonpbhelper.UnmarshalError{Path: "Patient.contained[0].ofType(Observation).status", Details: `code type mismatch`, Diagnostics: `"foo" is not a ObservationStatusCode`},
[]fhirversion.Version{fhirversion.DSTU2, fhirversion.STU3},
[]fhirversion.Version{fhirversion.STU3},
},
}
for _, test := range tests {
Expand Down

0 comments on commit 49d23bf

Please sign in to comment.