dimanche 13 août 2017

golang should this be an integration testing?

I have a method which implements the a database interface, that method inserts an 'object' into the database.

type database interface {
    createLog(logDoc) (bool, error)
}


type mongo struct {
    database   string
    collection string
}

func (m mongo) createLog(l logDoc) (bool, error) {

    s, err := mgo.Dial("mongo")

    defer s.Close()

    if err != nil {
        return false, err
    }

     err = s.DB(m.database).C(m.collection).Insert(l)
     if err != nil {
        return false, err
     }

     return true, nil
}

I want to be able to test the createLog method, how can I do this? should it be an integration test? if so what would be the your approach?

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire