Complete package for generating ocds structs (with extensions) in golang

This commit is contained in:
bwilliams committed 2026-10-01 14:50:07 +01:00
1 parent da726550d4
commit 35974fa070
47 files changed
+9861 -299

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package findtender
import (
"encoding/json"
"os"
"reflect"
"testing"
)
// TestRoundTrip decodes a release package that uses several extensions and
// checks that re-encoding it loses nothing. Numeric IDs are the one expected
// change: ID always encodes as a string.
func TestRoundTrip(t *testing.T) {
in, err := os.ReadFile("testdata/release-package.json")
if err != nil {
t.Fatal(err)
}
var pkg ReleasePackage
if err := json.Unmarshal(in, &pkg); err != nil {
t.Fatal(err)
}
r := pkg.Releases[0]
if got := r.Tender.Items[0].ID; got != "1" {
t.Errorf("numeric item id: got %q, want \"1\"", got)
}
if !*r.Tender.Lots[0].Suitability.SME {
t.Error("lot suitability lost")
}
if got := r.Contracts[0].Implementation.PerformanceFailures[0].ID; got != "PF1" {
t.Errorf("performance failure: got %q", got)
}
out, err := json.Marshal(pkg)
if err != nil {
t.Fatal(err)
}
var want, got any
json.Unmarshal(in, &want)
json.Unmarshal(out, &got)
// Normalise the one numeric ID in the fixture before comparing.
want.(map[string]any)["releases"].([]any)[0].(map[string]any)["tender"].(map[string]any)["items"].([]any)[0].(map[string]any)["id"] = "1"
if !reflect.DeepEqual(want, got) {
t.Fatalf("round trip changed the data:\n%s", out)
}
}