Hi all. Help plz with testing. I have a file dao.go:
package model_dao
import "io/ioutil"
const fileExtension = ".txt"
type Page struct {
Title string
Body []byte
}
func (p Page) SaveAsFile() (e error) {
p.Title = p.Title + fileExtension
return ioutil.WriteFile(p.Title, p.Body, 0600)
}
func LoadFromFile(title string) (*Page, error) {
fileName := title + fileExtension
body, err := ioutil.ReadFile(fileName)
if err != nil {
return nil, err
}
return &Page{title, body}, nil
}
And a test file dao_test.go:
package model_dao_test
import (
"shopserver/model/dao"
"testing"
)
func TestDAOFileWorks(t *testing.T) {
TITLE := "test"
BODY := []byte("Hello, World!!")
p := &model_dao.Page{TITLE, BODY}
p.SaveAsFile()
p, _ = model_dao.LoadFromFile(TITLE)
result := p.Body
if string(BODY) != string(result) {
t.Error("Body", BODY, "saved.\n", "Load:", result)
}
}
Here I test all 2 methods from Page, but after testing I see a message:
Tell me plz - why only 85.7%? Where he get this numbers and how to get 100%?
Aucun commentaire:
Enregistrer un commentaire