Ver código fonte

fixed the nonfunctional tests from lastnight

aeth 3 meses atrás
pai
commit
db5092ae82
2 arquivos alterados com 9 adições e 4 exclusões
  1. 2 2
      pkg/storage/storage.go
  2. 7 2
      pkg/storage/storage_test.go

+ 2 - 2
pkg/storage/storage.go

@@ -346,7 +346,7 @@ func (s *SQLiteRepo) GetImage(id Identifier) (Image, error) {
 	row := s.db.QueryRow("SELECT * FROM images WHERE id = ?", id)
 	var rowNum int
 	var title, location, desc, created string
-	if err := row.Scan(&rowNum, &title, &location, &desc, &created); err != nil {
+	if err := row.Scan(&rowNum, &id, &title, &location, &desc, &created); err != nil {
 		if errors.Is(err, sql.ErrNoRows) {
 			return Image{}, ErrNotExists
 		}
@@ -578,7 +578,7 @@ func (s *SQLiteRepo) AllDocuments() []Document {
 	all := []Document{}
 	for rows.Next() {
 		var post Document
-		if err := rows.Scan(&post.Ident, &post.Title, &post.Created, &post.Body, &post.Sample); err != nil {
+		if err := rows.Scan(&post.Row, &post.Ident, &post.Title, &post.Created, &post.Body, &post.Category, &post.Sample); err != nil {
 			fmt.Printf("There was an error getting all documents. %s", err.Error())
 			return nil
 		}

+ 7 - 2
pkg/storage/storage_test.go

@@ -254,7 +254,6 @@ func TestGetImage(t *testing.T) {
 	}
 	tmp := t.TempDir()
 	testImageLoc := path.Join(tmp, "test.jpg")
-	os.WriteFile(testImageLoc, []byte("abc123xyz098"), os.ModePerm)
 	for _, tc := range []testcase{
 		{
 			seed: Image{
@@ -263,6 +262,7 @@ func TestGetImage(t *testing.T) {
 				Location: testImageLoc,
 				Desc:     "description",
 				Created:  "2024-12-31",
+				Data:     []byte("abc123xyz098"),
 			},
 		},
 	} {
@@ -270,6 +270,7 @@ func TestGetImage(t *testing.T) {
 		if err != nil {
 			t.Error(err)
 		}
+		os.WriteFile(tc.seed.Location, tc.seed.Data, os.ModePerm)
 		got, err := testDb.GetImage(tc.seed.Ident)
 		if err != nil {
 			t.Error(err)
@@ -291,19 +292,23 @@ func TestGetAllImages(t *testing.T) {
 					Ident:    Identifier("abc123"),
 					Title:    "xyz098",
 					Location: path.Join(tmp, "1.jpg"),
+					Data:     []byte("abc123xyz098"),
+					Created:  "2024-12-31",
 					Desc:     "description",
 				},
 				{
 					Ident:    Identifier("xyz098"),
 					Title:    "abc123",
 					Location: path.Join(tmp, "2.jpg"),
+					Data:     []byte("abc123xyz098"),
+					Created:  "2024-12-31",
 					Desc:     "description",
 				},
 			},
 		},
 	} {
 		for i := range tc.seed {
-			_, err := db.Exec("INSERT INTO images (id, title, location, desc, created) VALUES (?,?,?,?,?)", tc.seed[i].Ident, tc.seed[1].Title, tc.seed[2].Location, tc.seed[3].Desc, "2024-12-31")
+			_, err := db.Exec("INSERT INTO images (id, title, location, desc, created) VALUES (?,?,?,?,?)", string(tc.seed[i].Ident), tc.seed[i].Title, tc.seed[i].Location, tc.seed[i].Desc, tc.seed[i].Created)
 			if err != nil {
 				t.Error(err)
 			}