Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Mar 2, 2024
1 parent fb3b95b commit edab952
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
6 changes: 5 additions & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func TestSaveAndLoadFromSQLite(t *testing.T) {
if err != nil {
t.Errorf("InitializeSQLite returned error: %v", err)
}
defer DeleteSQLite(db, "test")

// Test LoadFromSQLite with existing data in the database
expected := []StreamInfo{{
Expand Down Expand Up @@ -74,6 +73,11 @@ func TestSaveAndLoadFromSQLite(t *testing.T) {
t.Errorf("GetStreams returned %+v, expected %+v", result[i], expectedStream)
}
}

err = DeleteSQLite(db, "test")
if err != nil {
t.Errorf("DeleteSQLite returned error: %v", err)
}
}

// streamInfoEqual checks if two StreamInfo objects are equal.
Expand Down
5 changes: 3 additions & 2 deletions m3u/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package m3u

import (
"database/sql"
"fmt"
"log"
"m3u-stream-merger/database"
Expand All @@ -12,8 +13,8 @@ func generateStreamURL(baseUrl string, title string) string {
return fmt.Sprintf("%s/%s.mp4\n", baseUrl, utils.GetStreamUID(title))
}

func GenerateM3UContent(w http.ResponseWriter, r *http.Request) {
streams, err := database.GetStreams()
func GenerateM3UContent(w http.ResponseWriter, r *http.Request, db *sql.DB) {
streams, err := database.GetStreams(db)
if err != nil {
log.Println(fmt.Errorf("GetStreams error: %v", err))
}
Expand Down
18 changes: 14 additions & 4 deletions m3u/m3u_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestGenerateM3UContent(t *testing.T) {
if err != nil {
t.Errorf("InitializeSQLite returned error: %v", err)
}
defer database.DeleteSQLite(db, "test")

_, err = database.InsertStream(db, stream)
if err != nil {
Expand All @@ -39,7 +38,9 @@ func TestGenerateM3UContent(t *testing.T) {

// Create a ResponseRecorder to record the response
rr := httptest.NewRecorder()
handler := http.HandlerFunc(GenerateM3UContent)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
GenerateM3UContent(w, r, db)
})

// Call the ServeHTTP method of the handler to execute the test
handler.ServeHTTP(rr, req)
Expand All @@ -65,6 +66,11 @@ func TestGenerateM3UContent(t *testing.T) {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expectedContent)
}

err = database.DeleteSQLite(db, "test")
if err != nil {
t.Errorf("DeleteSQLite returned error: %v", err)
}
}

func TestParseM3UFromURL(t *testing.T) {
Expand Down Expand Up @@ -92,10 +98,9 @@ http://example.com/fox
if err != nil {
t.Errorf("InitializeSQLite returned error: %v", err)
}
defer database.DeleteSQLite(db, "test")

// Test the parseM3UFromURL function with the mock server URL
err = ParseM3UFromURL(mockServer.URL, 0, 1)
err = ParseM3UFromURL(db, mockServer.URL, 0, 1)
if err != nil {
t.Errorf("Error parsing M3U from URL: %v", err)
}
Expand Down Expand Up @@ -149,6 +154,11 @@ http://example.com/fox
t.FailNow()
}
}

err = database.DeleteSQLite(db, "test")
if err != nil {
t.Errorf("DeleteSQLite returned error: %v", err)
}
}

// streamInfoEqual checks if two StreamInfo objects are equal.
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ func main() {
}

// HTTP handlers
http.HandleFunc("/playlist.m3u", m3u.GenerateM3UContent)
http.HandleFunc("/playlist.m3u", func(w http.ResponseWriter, r *http.Request) {
m3u.GenerateM3UContent(w, r, db)
})
http.HandleFunc("/stream/", func(w http.ResponseWriter, r *http.Request) {
mp4Handler(w, r, db)
})
Expand Down

0 comments on commit edab952

Please sign in to comment.