Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Nov 7, 2024
1 parent 969a585 commit f13150d
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions migrations/kdvh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/jackc/pgx/v5/pgxpool"
"github.com/joho/godotenv"
"github.com/rickb777/period"
// "github.com/rickb777/period"

"migrate/kdvh"
)
Expand All @@ -17,37 +17,23 @@ const LARD_STRING string = "host=localhost user=postgres dbname=postgres passwor
// const CONN_STRING string = "postgresql://postgres:postgres@localhost/postgres"

func mockConfig(t *ImportTest, db *kdvh.KDVH) *kdvh.ImportConfig {
paramKey := kdvh.ParamKey{
ElemCode: t.elem,
TableName: t.table,
}

key := kdvh.KDVHKey{ParamKey: paramKey, Station: t.station}

config := kdvh.ImportConfig{
Tables: []string{t.table},
Stations: []string{fmt.Sprint(t.station)},
Elements: []string{t.elem},
BaseDir: "./tests",
HasHeader: true,
Sep: ";",
OffsetMap: map[kdvh.ParamKey]period.Period{paramKey: {}},
KDVHMap: map[kdvh.KDVHKey]*kdvh.MetaKDVH{key: {
TableName: t.table,
Station: t.station,
ElemCode: t.elem,
// FromTime: &time.Time{},
// ToTime: &time.Time{},
}},
}
config.CacheStinfo(db)

config.CacheMetadata(db)
return &config

}

type ImportTest struct {
table string
station int64
station int32
elem string
expectedRows int64
}
Expand All @@ -59,7 +45,7 @@ func TestImportKDVH(t *testing.T) {
return
}

db := kdvh.Init()
db := kdvh.InitDB()

pool, err := pgxpool.New(context.TODO(), LARD_STRING)
if err != nil {
Expand All @@ -71,6 +57,15 @@ func TestImportKDVH(t *testing.T) {
{table: "T_MDATA", station: 12345, elem: "TA", expectedRows: 2644},
}

// type Out struct {
// id int
// stnr int
// param int
// typ int
// lvl int
// sensor int
// }
//
for _, c := range testCases {
config := mockConfig(&c, db)
table, ok := db.Tables[c.table]
Expand All @@ -82,6 +77,25 @@ func TestImportKDVH(t *testing.T) {
if insertedRows != c.expectedRows {
t.Fail()
}

// test_query := "SELECT * FROM labels.met WHERE ($1::int IS NULL OR timeseries = $1)"
// res, err := pool.Query(context.TODO(), test_query, nil)
// if err != nil {
// t.Log(err)
// t.Fail()
// }
//
// for res.Next() {
// o := Out{}
// if err = res.Scan(&o.id, &o.stnr, &o.param, &o.typ, &o.lvl, &o.sensor); err != nil {
// t.Log(err)
// t.Fail()
// }
// fmt.Println(o)
// }
//
// res.Close()
//
}

}

0 comments on commit f13150d

Please sign in to comment.