Swagger for import-exoprt

This commit is contained in:
breel
2020-07-25 20:20:12 -06:00
parent 09507d38e9
commit b423adde4a
8 changed files with 350 additions and 32 deletions

View File

@@ -81,7 +81,16 @@ func (o One) MarshalBSON() ([]byte, error) {
default:
return nil, fmt.Errorf("bad connections type %T", m[Connections])
}
delete(connections, "")
for k := range connections {
if k == "" {
continue
}
if o.Connections[k].Name == "" {
p := o.Connections[k]
p.Name = k
o.Connections[k] = p
}
b, err := bson.Marshal(o.Connections[k])
if err != nil {
return nil, err

View File

@@ -71,3 +71,65 @@ func TestOneMarshalBSON(t *testing.T) {
})
}
}
func TestOneMarshalBSONBadConnections(t *testing.T) {
t.Run("connections has an empty string for a key that should die", func(t *testing.T) {
input := One{Name: "hello", Connections: map[string]One{"": One{Name: "teehee"}}}
b, err := bson.Marshal(input)
if err != nil {
t.Fatal(err)
}
output := One{}
if err := bson.Unmarshal(b, &output); err != nil {
t.Fatal(err)
}
if len(output.Connections) != 0 {
t.Fatal(output.Connections)
}
input.Connections = nil
output.Connections = nil
input.Modified = 0
output.Modified = 0
if fmt.Sprint(input) != fmt.Sprint(output) {
t.Fatal(input, output)
}
})
t.Run("connections has a key but empty name that should correct", func(t *testing.T) {
input := One{Name: "hello", Connections: map[string]One{"teehee": One{Name: ""}}}
b, err := bson.Marshal(input)
if err != nil {
t.Fatal(err)
}
output := One{}
if err := bson.Unmarshal(b, &output); err != nil {
t.Fatal(err)
}
if len(output.Connections) != 1 {
t.Fatal(output.Connections)
} else {
for k := range output.Connections {
if k != output.Connections[k].Name {
t.Fatal(k, output.Connections)
}
}
}
input.Connections = nil
output.Connections = nil
input.Modified = 0
output.Modified = 0
if fmt.Sprint(input) != fmt.Sprint(output) {
t.Fatal(input, output)
}
})
}