-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RR-53] handle errors and save to log table
- Loading branch information
1 parent
9985aa9
commit b97bb3f
Showing
4 changed files
with
188 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package dispatcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package store | ||
|
||
import ( | ||
"database/sql" | ||
_ "github.com/go-sql-driver/mysql" | ||
"simple-go-app/internal/logging" | ||
"testing" | ||
) | ||
|
||
// test adding a log entry | ||
func TestStore_AddLog(t *testing.T) { | ||
dbHost := "localhost" | ||
dbPort := "3306" | ||
dbUser := "sail" | ||
dbPassword := "password" | ||
dbName := "rapid_research" | ||
|
||
db, err := sql.Open("mysql", dbUser+":"+dbPassword+"@tcp("+dbHost+":"+dbPort+")/"+dbName) | ||
if err != nil { | ||
logging.ErrorLogger.Println("Error opening database:", err) | ||
} | ||
s := New(db) | ||
|
||
err = s.SaveLog(Log{ | ||
Level: "info", | ||
UserMessage: "test", | ||
FullLog: "test", | ||
Stage: "test", | ||
UserID: 1, | ||
ScreenID: 1, | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
if err != nil { | ||
t.Errorf("Error adding log entry: %v", err) | ||
} | ||
} |