diff --git a/api/v2/api-v2.go b/api/v2/api-v2.go index f1429e34..7d38174a 100644 --- a/api/v2/api-v2.go +++ b/api/v2/api-v2.go @@ -196,7 +196,7 @@ func convert(s *uuid.ServerAnnotations) *api.Annotations { // API and should be retired with the annotation-service once the annotation // export processes are complete. func ConvertAnnotationsToServerAnnotations(a *api.Annotations) *uuid.ServerAnnotations { - return &uuid.ServerAnnotations{ + s := &uuid.ServerAnnotations{ Geo: &uuid.Geolocation{ ContinentCode: a.Geo.ContinentCode, CountryCode: a.Geo.CountryCode, @@ -221,12 +221,15 @@ func ConvertAnnotationsToServerAnnotations(a *api.Annotations) *uuid.ServerAnnot ASNumber: a.Network.ASNumber, ASName: a.Network.ASName, Missing: a.Network.Missing, - // M-Lab Servers only define one System. - Systems: []uuid.System{ - {ASNs: a.Network.Systems[0].ASNs}, - }, }, } + if len(a.Network.Systems) > 0 { + // M-Lab Servers only define one System. + s.Network.Systems = []uuid.System{ + {ASNs: a.Network.Systems[0].ASNs}, + } + } + return s } // ConvertAnnotationsToClientAnnotations accepts an annotation from the v2 API diff --git a/api/v2/api-v2_test.go b/api/v2/api-v2_test.go index 26b4a4c6..3b118ca6 100644 --- a/api/v2/api-v2_test.go +++ b/api/v2/api-v2_test.go @@ -217,6 +217,14 @@ func TestConvertAnnotationsToServerAnnotations(t *testing.T) { }, }, } + empty := &types.Annotations{ + Geo: &types.GeolocationIP{ + Missing: true, + }, + Network: &types.ASData{ + Missing: true, + }, + } expectedServer := &uuid.ServerAnnotations{ // NOTE: the Site and Machine fields will not be specified. Geo: &uuid.Geolocation{ @@ -241,6 +249,14 @@ func TestConvertAnnotationsToServerAnnotations(t *testing.T) { }, }, } + expectedEmpty := &uuid.ServerAnnotations{ + Geo: &uuid.Geolocation{ + Missing: true, + }, + Network: &uuid.Network{ + Missing: true, + }, + } expectedClient := &uuid.ClientAnnotations{ Geo: &uuid.Geolocation{ ContinentCode: "NA", @@ -269,6 +285,10 @@ func TestConvertAnnotationsToServerAnnotations(t *testing.T) { if !reflect.DeepEqual(gs, expectedServer) { t.Errorf("ConvertAnnotationsToServerAnnotations() = %v, want %v", gs, expectedServer) } + gempty := api.ConvertAnnotationsToServerAnnotations(empty) + if !reflect.DeepEqual(gempty, expectedEmpty) { + t.Errorf("ConvertAnnotationsToServerAnnotations() = %v, want %v", gempty, expectedEmpty) + } gc := api.ConvertAnnotationsToClientAnnotations(a) if !reflect.DeepEqual(gc, expectedClient) {