Fix some more build errors
This commit is contained in:
parent
c4c2ef8979
commit
d8d04c5acc
@ -11,6 +11,7 @@ sources:
|
|||||||
packages:
|
packages:
|
||||||
- wget
|
- wget
|
||||||
- build-essential
|
- build-essential
|
||||||
|
- sqlite3
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- install_go: |
|
- install_go: |
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
func (p Profile) SaveImage(img scraper.Image) (sql.Result, error) {
|
func (p Profile) SaveImage(img scraper.Image) (sql.Result, error) {
|
||||||
if img.ID == 0 {
|
if img.ID == 0 {
|
||||||
// New image
|
// New image
|
||||||
return p.DB.Exec("insert into images (tweet_id, filename) values (?, ?)", img.TweetID, img.Filename)
|
return p.DB.Exec("insert into images (tweet_id, filename) values (?, ?) on conflict do nothing", img.TweetID, img.Filename)
|
||||||
} else {
|
} else {
|
||||||
// Updating an existing image
|
// Updating an existing image
|
||||||
return p.DB.Exec("update images set filename=?, is_downloaded=? where rowid=?", img.Filename, img.IsDownloaded, img.ID)
|
return p.DB.Exec("update images set filename=?, is_downloaded=? where rowid=?", img.Filename, img.IsDownloaded, img.ID)
|
||||||
@ -37,7 +37,7 @@ func (p Profile) SaveImage(img scraper.Image) (sql.Result, error) {
|
|||||||
func (p Profile) SaveVideo(vid scraper.Video) (sql.Result, error) {
|
func (p Profile) SaveVideo(vid scraper.Video) (sql.Result, error) {
|
||||||
if vid.ID == 0 {
|
if vid.ID == 0 {
|
||||||
// New image
|
// New image
|
||||||
return p.DB.Exec("insert into videos (tweet_id, filename) values (?, ?)", vid.TweetID, vid.Filename)
|
return p.DB.Exec("insert into videos (tweet_id, filename) values (?, ?) on conflict do nothing", vid.TweetID, vid.Filename)
|
||||||
} else {
|
} else {
|
||||||
// Updating an existing image
|
// Updating an existing image
|
||||||
return p.DB.Exec("update videos set filename=?, is_downloaded=? where rowid=?", vid.Filename, vid.IsDownloaded, vid.ID)
|
return p.DB.Exec("update videos set filename=?, is_downloaded=? where rowid=?", vid.Filename, vid.IsDownloaded, vid.ID)
|
||||||
|
@ -57,6 +57,51 @@ func TestSaveAndLoadImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change an Image, save the changes, reload it, and check if it comes back the same
|
||||||
|
*/
|
||||||
|
func TestModifyImage(t *testing.T) {
|
||||||
|
profile_path := "test_profiles/TestMediaQueries"
|
||||||
|
profile := create_or_load_profile(profile_path)
|
||||||
|
|
||||||
|
tweet := create_stable_tweet()
|
||||||
|
img := tweet.Images[0]
|
||||||
|
|
||||||
|
if img.ID != 1 {
|
||||||
|
t.Fatalf("Got the wrong image back: wanted ID %d, got %d", 1, img.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
img.Filename = "local/sdfjk.jpg"
|
||||||
|
img.IsDownloaded = true
|
||||||
|
|
||||||
|
// Save the changes
|
||||||
|
result, err := profile.SaveImage(img)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
rows_affected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if rows_affected != 1 {
|
||||||
|
t.Errorf("Expected 1 row changed, but got %d", rows_affected)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload it
|
||||||
|
imgs, err := profile.GetImagesForTweet(tweet)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not load images: %s", err.Error())
|
||||||
|
}
|
||||||
|
new_img := imgs[0]
|
||||||
|
if new_img.ID != img.ID {
|
||||||
|
t.Fatalf("Got the wrong image back: wanted ID %d, got %d", 1, new_img.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff := deep.Equal(img, new_img); diff != nil {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an Video, save it, reload it, and make sure it comes back the same
|
* Create an Video, save it, reload it, and make sure it comes back the same
|
||||||
@ -102,3 +147,48 @@ func TestSaveAndLoadVideo(t *testing.T) {
|
|||||||
t.Error(diff)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change an Image, save the changes, reload it, and check if it comes back the same
|
||||||
|
*/
|
||||||
|
func TestModifyVideo(t *testing.T) {
|
||||||
|
profile_path := "test_profiles/TestMediaQueries"
|
||||||
|
profile := create_or_load_profile(profile_path)
|
||||||
|
|
||||||
|
tweet := create_stable_tweet()
|
||||||
|
vid := tweet.Videos[0]
|
||||||
|
|
||||||
|
if vid.ID != 1 {
|
||||||
|
t.Fatalf("Got the wrong video back: wanted ID %d, got %d", 1, vid.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
vid.Filename = "local/sdfjk.jpg"
|
||||||
|
vid.IsDownloaded = true
|
||||||
|
|
||||||
|
// Save the changes
|
||||||
|
result, err := profile.SaveVideo(vid)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
rows_affected, err := result.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if rows_affected != 1 {
|
||||||
|
t.Errorf("Expected 1 row changed, but got %d", rows_affected)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload it
|
||||||
|
vids, err := profile.GetVideosForTweet(tweet)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not load videos: %s", err.Error())
|
||||||
|
}
|
||||||
|
new_vid := vids[0]
|
||||||
|
if new_vid.ID != vid.ID {
|
||||||
|
t.Fatalf("Got the wrong video back: wanted ID %d, got %d", 1, new_vid.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff := deep.Equal(vid, new_vid); diff != nil {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user