Skip to content

Commit

Permalink
test: Add tests for the Upsert function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 21, 2024
1 parent d11c97f commit 4638b06
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cmd/database/query/upsert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package query

import (
"os"
"testing"

"github.com/Dobefu/csb/cmd/database"
"github.com/Dobefu/csb/cmd/database/structs"
"github.com/Dobefu/csb/cmd/init_env"
"github.com/Dobefu/csb/cmd/logger"
"github.com/stretchr/testify/assert"
)

func TestUpsert(t *testing.T) {
var err error

init_env.Main("../../../.env.test")
err = database.Connect()
assert.Equal(t, nil, err)

err = resetDb()
assert.Equal(t, nil, err)

err = Upsert("state", []structs.QueryValue{
{
Name: "name",
Value: "test",
},
{
Name: "value",
Value: "test",
},
})
assert.Equal(t, nil, err)

dbType := os.Getenv("DB_TYPE")
os.Setenv("DB_TYPE", "bogus")
logger.SetExitOnFatal(false)

err = Upsert("state", []structs.QueryValue{})
assert.Equal(t, nil, err)

os.Setenv("DB_TYPE", dbType)
}

0 comments on commit 4638b06

Please sign in to comment.