offline-twitter/pkg/persistence/versions_test.go

34 lines
1.0 KiB
Go
Raw Normal View History

2021-11-22 16:55:27 -08:00
package persistence_test
import (
"testing"
2022-03-13 17:09:43 -07:00
2021-11-22 16:55:27 -08:00
"os"
"github.com/stretchr/testify/require"
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence"
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
2021-11-22 16:55:27 -08:00
)
func TestVersionUpgrade(t *testing.T) {
require := require.New(t)
2021-11-22 16:55:27 -08:00
profile_path := "test_profiles/TestVersions"
if file_exists(profile_path) {
err := os.RemoveAll(profile_path)
require.NoError(err)
2021-11-22 16:55:27 -08:00
}
profile := create_or_load_profile(profile_path)
test_migration := "insert into tweets (id, user_id, text) values (21250554358298342, -1, 'awefjk')"
test_tweet_id := scraper.TweetID(21250554358298342)
require.False(profile.IsTweetInDatabase(test_tweet_id), "Test tweet shouldn't be in db yet")
2021-11-22 16:55:27 -08:00
persistence.MIGRATIONS = append(persistence.MIGRATIONS, test_migration)
2022-03-13 17:09:43 -07:00
err := profile.UpgradeFromXToY(persistence.ENGINE_DATABASE_VERSION, persistence.ENGINE_DATABASE_VERSION+1)
require.NoError(err)
2021-11-22 16:55:27 -08:00
require.True(profile.IsTweetInDatabase(test_tweet_id), "Migration should have created the tweet, but it didn't")
2021-11-22 16:55:27 -08:00
}