Swagger for import-exoprt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user