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