Swagger for import-exoprt
This commit is contained in:
@@ -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