57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMeasurementWorkflow(t *testing.T) {
|
|
tmpfile, err := ioutil.TempFile("", "dbtest")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(tmpfile.Name())
|
|
|
|
tmpdir, err := ioutil.TempDir("", "oonitest")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
sess, err := Connect(tmpfile.Name())
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
result, err := CreateResult(sess, tmpdir, Result{
|
|
TestGroupName: "websites",
|
|
StartTime: time.Now().UTC(),
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
msmtTemplate := Measurement{
|
|
ReportID: sql.NullString{String: "", Valid: false},
|
|
TestName: "antani",
|
|
ResultID: result.ID,
|
|
ReportFilePath: tmpdir,
|
|
}
|
|
m1, err := CreateMeasurement(sess, msmtTemplate, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var m2 Measurement
|
|
err = sess.Collection("measurements").Find("id", m1.ID).One(&m2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m2.ResultID != m1.ResultID {
|
|
t.Error("result_id mismatch")
|
|
}
|
|
|
|
}
|