mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-16 18:41:03 +01:00
fixed the DB error, was stupid mistake in test-only code
This commit is contained in:
parent
f1303849cf
commit
0a3d60769c
@ -26,7 +26,6 @@ func apiSubmitHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("handler GLOBAL_DB=%#v\n", GLOBAL_DB)
|
||||
GLOBAL_DB.Create(&entry)
|
||||
}
|
||||
|
||||
@ -81,7 +80,6 @@ func apiERegister(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func OpenDB() (*gorm.DB, error) {
|
||||
fmt.Println("OPENDDDDDDDDDDDBBBBBBBBBBBB")
|
||||
if shared.IsTestEnvironment() {
|
||||
return shared.OpenLocalSqliteDb()
|
||||
}
|
||||
@ -120,6 +118,10 @@ func apiSearchHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func init() {
|
||||
InitDB()
|
||||
}
|
||||
|
||||
func InitDB() {
|
||||
var err error
|
||||
GLOBAL_DB, err = OpenDB()
|
||||
if err != nil {
|
||||
@ -133,12 +135,9 @@ func init() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
GLOBAL_DB.Create(&shared.HistoryEntry{Hostname: "foo"})
|
||||
fmt.Printf("init GLOBAL_DB=%#v\n", GLOBAL_DB)
|
||||
}
|
||||
|
||||
func main() {
|
||||
GLOBAL_DB.Create(&shared.HistoryEntry{Hostname: "foo"})
|
||||
fmt.Println("Listening on localhost:8080")
|
||||
http.HandleFunc("/api/v1/submit", apiSubmitHandler)
|
||||
http.HandleFunc("/api/v1/search", apiSearchHandler)
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
// "io/ioutil"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@ -14,6 +14,7 @@ import (
|
||||
func TestSubmitThenQuery(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
InitDB()
|
||||
shared.Check(t, shared.Setup(0, []string{}))
|
||||
|
||||
// Submit an entry
|
||||
@ -24,193 +25,194 @@ func TestSubmitThenQuery(t *testing.T) {
|
||||
submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiSubmitHandler(nil, submitReq)
|
||||
// Also submit one for another user
|
||||
// otherEntry := *entry
|
||||
// otherEntry.UserSecret = "aaaaaaaaa"
|
||||
// otherEntry.Command = "other"
|
||||
// reqBody, err = json.Marshal(otherEntry)
|
||||
// shared.Check(t, err)
|
||||
// submitReq = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
// apiSubmitHandler(nil, submitReq)
|
||||
|
||||
t.Fatalf("aaaaaaaaaaa")
|
||||
otherEntry := *entry
|
||||
otherEntry.UserSecret = "aaaaaaaaa"
|
||||
otherEntry.Command = "other"
|
||||
reqBody, err = json.Marshal(otherEntry)
|
||||
shared.Check(t, err)
|
||||
submitReq = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiSubmitHandler(nil, submitReq)
|
||||
|
||||
// Retrieve the entry
|
||||
// secret, err := shared.GetUserSecret()
|
||||
// shared.Check(t, err)
|
||||
// w := httptest.NewRecorder()
|
||||
// searchReq := httptest.NewRequest(http.MethodGet, "/?user_secret="+secret, nil)
|
||||
// apiSearchHandler(w, searchReq)
|
||||
// res := w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err := ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// var retrievedEntries []*shared.HistoryEntry
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 1 {
|
||||
// t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// dbEntry := retrievedEntries[0]
|
||||
// if dbEntry.UserSecret != "" {
|
||||
// t.Fatalf("Response contains a user secret: %#v", *dbEntry)
|
||||
// }
|
||||
// entry.UserSecret = ""
|
||||
// if !shared.EntryEquals(*dbEntry, *entry) {
|
||||
// t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
// }
|
||||
secret, err := shared.GetUserSecret()
|
||||
shared.Check(t, err)
|
||||
w := httptest.NewRecorder()
|
||||
searchReq := httptest.NewRequest(http.MethodGet, "/?user_secret="+secret, nil)
|
||||
apiSearchHandler(w, searchReq)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
var retrievedEntries []*shared.HistoryEntry
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 1 {
|
||||
t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
}
|
||||
dbEntry := retrievedEntries[0]
|
||||
if dbEntry.UserSecret != "" {
|
||||
t.Fatalf("Response contains a user secret: %#v", *dbEntry)
|
||||
}
|
||||
entry.UserSecret = ""
|
||||
if !shared.EntryEquals(*dbEntry, *entry) {
|
||||
t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestNoUserSecretGivesNoResults(t *testing.T) {
|
||||
// // Set up
|
||||
// defer shared.BackupAndRestore(t)()
|
||||
// shared.Check(t, shared.Setup(0, []string{}))
|
||||
func TestNoUserSecretGivesNoResults(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
InitDB()
|
||||
shared.Check(t, shared.Setup(0, []string{}))
|
||||
|
||||
// // Submit an entry
|
||||
// entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls / ", "1641774958326745663"})
|
||||
// shared.Check(t, err)
|
||||
// reqBody, err := json.Marshal(entry)
|
||||
// shared.Check(t, err)
|
||||
// submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
// apiSubmitHandler(nil, submitReq)
|
||||
// Submit an entry
|
||||
entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls / ", "1641774958326745663"})
|
||||
shared.Check(t, err)
|
||||
reqBody, err := json.Marshal(entry)
|
||||
shared.Check(t, err)
|
||||
submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiSubmitHandler(nil, submitReq)
|
||||
|
||||
// // Retrieve entries with no user secret
|
||||
// w := httptest.NewRecorder()
|
||||
// searchReq := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
// apiSearchHandler(w, searchReq)
|
||||
// res := w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err := ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// var retrievedEntries []*shared.HistoryEntry
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 0 {
|
||||
// t.Fatalf("Expected to retrieve 0 entries, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// }
|
||||
// Retrieve entries with no user secret
|
||||
w := httptest.NewRecorder()
|
||||
searchReq := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
apiSearchHandler(w, searchReq)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
var retrievedEntries []*shared.HistoryEntry
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 0 {
|
||||
t.Fatalf("Expected to retrieve 0 entries, found %d, results[0]=%#v", len(retrievedEntries), retrievedEntries[0])
|
||||
}
|
||||
}
|
||||
|
||||
// func TestSearchQuery(t *testing.T) {
|
||||
// // Set up
|
||||
// defer shared.BackupAndRestore(t)()
|
||||
// shared.Check(t, shared.Setup(0, []string{}))
|
||||
func TestSearchQuery(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
InitDB()
|
||||
shared.Check(t, shared.Setup(0, []string{}))
|
||||
|
||||
// // Submit an entry that we'll match
|
||||
// entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls /bar ", "1641774958326745663"})
|
||||
// shared.Check(t, err)
|
||||
// reqBody, err := json.Marshal(entry)
|
||||
// shared.Check(t, err)
|
||||
// submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
// apiSubmitHandler(nil, submitReq)
|
||||
// // Submit an entry that we won't match
|
||||
// entry, err = shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls /foo ", "1641774958326745663"})
|
||||
// shared.Check(t, err)
|
||||
// reqBody, err = json.Marshal(entry)
|
||||
// shared.Check(t, err)
|
||||
// submitReq = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
// apiSubmitHandler(nil, submitReq)
|
||||
// Submit an entry that we'll match
|
||||
entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls /bar ", "1641774958326745663"})
|
||||
shared.Check(t, err)
|
||||
reqBody, err := json.Marshal(entry)
|
||||
shared.Check(t, err)
|
||||
submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiSubmitHandler(nil, submitReq)
|
||||
// Submit an entry that we won't match
|
||||
entry, err = shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls /foo ", "1641774958326745663"})
|
||||
shared.Check(t, err)
|
||||
reqBody, err = json.Marshal(entry)
|
||||
shared.Check(t, err)
|
||||
submitReq = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiSubmitHandler(nil, submitReq)
|
||||
|
||||
// // Retrieve the entry
|
||||
// secret, err := shared.GetUserSecret()
|
||||
// shared.Check(t, err)
|
||||
// w := httptest.NewRecorder()
|
||||
// searchReq := httptest.NewRequest(http.MethodGet, "/?user_secret="+secret+"&query=foo", nil)
|
||||
// apiSearchHandler(w, searchReq)
|
||||
// res := w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err := ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// var retrievedEntries []*shared.HistoryEntry
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 1 {
|
||||
// t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// dbEntry := retrievedEntries[0]
|
||||
// if dbEntry.Command != "ls /foo" {
|
||||
// t.Fatalf("Response contains an unexpected command: %#v", *dbEntry)
|
||||
// }
|
||||
// }
|
||||
// Retrieve the entry
|
||||
secret, err := shared.GetUserSecret()
|
||||
shared.Check(t, err)
|
||||
w := httptest.NewRecorder()
|
||||
searchReq := httptest.NewRequest(http.MethodGet, "/?user_secret="+secret+"&query=foo", nil)
|
||||
apiSearchHandler(w, searchReq)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
var retrievedEntries []*shared.HistoryEntry
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 1 {
|
||||
t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
}
|
||||
dbEntry := retrievedEntries[0]
|
||||
if dbEntry.Command != "ls /foo" {
|
||||
t.Fatalf("Response contains an unexpected command: %#v", *dbEntry)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestESubmitThenQuery(t *testing.T) {
|
||||
// // Set up
|
||||
// defer shared.BackupAndRestore(t)()
|
||||
// shared.Check(t, shared.Setup(0, []string{}))
|
||||
func TestESubmitThenQuery(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
InitDB()
|
||||
shared.Check(t, shared.Setup(0, []string{}))
|
||||
|
||||
// // Submit a few entries for different devices
|
||||
// entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls / ", "1641774958326745663"})
|
||||
// shared.Check(t, err)
|
||||
// encEntry, err := shared.EncryptHistoryEntry("key", *entry)
|
||||
// shared.Check(t, err)
|
||||
// reqBody, err := json.Marshal([]shared.EncHistoryEntry{encEntry})
|
||||
// shared.Check(t, err)
|
||||
// submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
// apiESubmitHandler(nil, submitReq)
|
||||
// Submit a few entries for different devices
|
||||
entry, err := shared.BuildHistoryEntry([]string{"unused", "saveHistoryEntry", "120", " 123 ls / ", "1641774958326745663"})
|
||||
shared.Check(t, err)
|
||||
encEntry, err := shared.EncryptHistoryEntry("key", *entry)
|
||||
shared.Check(t, err)
|
||||
reqBody, err := json.Marshal([]shared.EncHistoryEntry{encEntry})
|
||||
shared.Check(t, err)
|
||||
submitReq := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(reqBody))
|
||||
apiESubmitHandler(nil, submitReq)
|
||||
|
||||
// // Query for device id 1
|
||||
// w := httptest.NewRecorder()
|
||||
// searchReq := httptest.NewRequest(http.MethodGet, "/?device_id="+shared.DeviceId("key", 1), nil)
|
||||
// apiEQueryHandler(w, searchReq)
|
||||
// res := w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err := ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// var retrievedEntries []*shared.EncHistoryEntry
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 1 {
|
||||
// t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// dbEntry := retrievedEntries[0]
|
||||
// if dbEntry.DeviceId != shared.DeviceId("key", 1) {
|
||||
// t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
// }
|
||||
// if dbEntry.UserId != shared.UserId("key") {
|
||||
// t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
// }
|
||||
// if dbEntry.ReadCount != 1 {
|
||||
// t.Fatalf("db.ReadCount should have been 1, was %v", dbEntry.ReadCount)
|
||||
// }
|
||||
// decEntry, err := shared.DecryptHistoryEntry("key", 1, *dbEntry)
|
||||
// shared.Check(t, err)
|
||||
// if !shared.EntryEquals(decEntry, *entry) {
|
||||
// t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
// }
|
||||
// Query for device id 1
|
||||
w := httptest.NewRecorder()
|
||||
searchReq := httptest.NewRequest(http.MethodGet, "/?device_id="+shared.DeviceId("key", 1), nil)
|
||||
apiEQueryHandler(w, searchReq)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
var retrievedEntries []*shared.EncHistoryEntry
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 1 {
|
||||
t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
}
|
||||
dbEntry := retrievedEntries[0]
|
||||
if dbEntry.DeviceId != shared.DeviceId("key", 1) {
|
||||
t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
}
|
||||
if dbEntry.UserId != shared.UserId("key") {
|
||||
t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
}
|
||||
if dbEntry.ReadCount != 1 {
|
||||
t.Fatalf("db.ReadCount should have been 1, was %v", dbEntry.ReadCount)
|
||||
}
|
||||
decEntry, err := shared.DecryptHistoryEntry("key", 1, *dbEntry)
|
||||
shared.Check(t, err)
|
||||
if !shared.EntryEquals(decEntry, *entry) {
|
||||
t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
}
|
||||
|
||||
// // Same for device id 2
|
||||
// w = httptest.NewRecorder()
|
||||
// searchReq = httptest.NewRequest(http.MethodGet, "/?device_id="+shared.DeviceId("key", 2), nil)
|
||||
// apiEQueryHandler(w, searchReq)
|
||||
// res = w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err = ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 1 {
|
||||
// t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// dbEntry = retrievedEntries[0]
|
||||
// if dbEntry.DeviceId != shared.DeviceId("key", 2) {
|
||||
// t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
// }
|
||||
// if dbEntry.UserId != shared.UserId("key") {
|
||||
// t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
// }
|
||||
// if dbEntry.ReadCount != 1 {
|
||||
// t.Fatalf("db.ReadCount should have been 1, was %v", dbEntry.ReadCount)
|
||||
// }
|
||||
// decEntry, err = shared.DecryptHistoryEntry("key", 2, *dbEntry)
|
||||
// shared.Check(t, err)
|
||||
// if !shared.EntryEquals(decEntry, *entry) {
|
||||
// t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
// }
|
||||
// Same for device id 2
|
||||
w = httptest.NewRecorder()
|
||||
searchReq = httptest.NewRequest(http.MethodGet, "/?device_id="+shared.DeviceId("key", 2), nil)
|
||||
apiEQueryHandler(w, searchReq)
|
||||
res = w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err = ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 1 {
|
||||
t.Fatalf("Expected to retrieve 1 entry, found %d", len(retrievedEntries))
|
||||
}
|
||||
dbEntry = retrievedEntries[0]
|
||||
if dbEntry.DeviceId != shared.DeviceId("key", 2) {
|
||||
t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
}
|
||||
if dbEntry.UserId != shared.UserId("key") {
|
||||
t.Fatalf("Response contains an incorrect device ID: %#v", *dbEntry)
|
||||
}
|
||||
if dbEntry.ReadCount != 1 {
|
||||
t.Fatalf("db.ReadCount should have been 1, was %v", dbEntry.ReadCount)
|
||||
}
|
||||
decEntry, err = shared.DecryptHistoryEntry("key", 2, *dbEntry)
|
||||
shared.Check(t, err)
|
||||
if !shared.EntryEquals(decEntry, *entry) {
|
||||
t.Fatalf("DB data is different than input! \ndb =%#v\ninput=%#v", *dbEntry, *entry)
|
||||
}
|
||||
|
||||
// // Bootstrap handler should return 3 entries, one for each device
|
||||
// w = httptest.NewRecorder()
|
||||
// searchReq = httptest.NewRequest(http.MethodGet, "/?user_id="+shared.UserId("key"), nil)
|
||||
// apiEBootstrapHandler(w, searchReq)
|
||||
// res = w.Result()
|
||||
// defer res.Body.Close()
|
||||
// data, err = ioutil.ReadAll(res.Body)
|
||||
// shared.Check(t, err)
|
||||
// shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
// if len(retrievedEntries) != 3 {
|
||||
// t.Fatalf("Expected to retrieve 3 entries, found %d", len(retrievedEntries))
|
||||
// }
|
||||
// Bootstrap handler should return 3 entries, one for each device
|
||||
w = httptest.NewRecorder()
|
||||
searchReq = httptest.NewRequest(http.MethodGet, "/?user_id="+shared.UserId("key"), nil)
|
||||
apiEBootstrapHandler(w, searchReq)
|
||||
res = w.Result()
|
||||
defer res.Body.Close()
|
||||
data, err = ioutil.ReadAll(res.Body)
|
||||
shared.Check(t, err)
|
||||
shared.Check(t, json.Unmarshal(data, &retrievedEntries))
|
||||
if len(retrievedEntries) != 3 {
|
||||
t.Fatalf("Expected to retrieve 3 entries, found %d", len(retrievedEntries))
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
@ -174,7 +174,6 @@ func IsTestEnvironment() bool {
|
||||
}
|
||||
|
||||
func OpenLocalSqliteDb() (*gorm.DB, error) {
|
||||
fmt.Printf("LOCAL SQLITE DB!\n")
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get user's home directory: %v", err)
|
||||
@ -183,7 +182,7 @@ func OpenLocalSqliteDb() (*gorm.DB, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create ~/.hishtory dir: %v", err)
|
||||
}
|
||||
db, err := gorm.Open(sqlite.Open(path.Join(homedir, HISHTORY_PATH, DB_PATH)), &gorm.Config{})
|
||||
db, err := gorm.Open(sqlite.Open(path.Join(homedir, HISHTORY_PATH, DB_PATH)), &gorm.Config{SkipDefaultTransaction: true,})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to the DB: %v", err)
|
||||
}
|
||||
@ -197,9 +196,6 @@ func OpenLocalSqliteDb() (*gorm.DB, error) {
|
||||
}
|
||||
db.AutoMigrate(&HistoryEntry{})
|
||||
db.AutoMigrate(&EncHistoryEntry{})
|
||||
|
||||
db.Create(&HistoryEntry{Hostname: "foo"})
|
||||
db.Create(&HistoryEntry{Hostname: "bar"}) // toDO: delete me
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user