Skip to content

Commit

Permalink
refactor test code
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Oct 3, 2024
1 parent 954d3d1 commit 596b747
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
36 changes: 0 additions & 36 deletions src/bunker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

uuid "github.com/hashicorp/go-uuid"
"github.com/julienschmidt/httprouter"
"github.com/securitybunker/databunker/src/storage"
)

var (
Expand Down Expand Up @@ -83,41 +82,6 @@ func helpConfigurationDump(token string) ([]byte, error) {
return helpServe0(request)
}

func init() {
log.Printf("**INIT*TEST*CODE***\n")
testDBFile := storage.CreateTestDB()
db, myRootToken, err := setupDB(&testDBFile, nil, "")
if err != nil {
log.Printf("Init error %s", err.Error())
}
rootToken = myRootToken
var cfg Config
cfile := "../databunker.yaml"
err = readConfFile(&cfg, &cfile)
cfg.SelfService.AppRecordChange = []string{"testapp", "super"}
if err != nil {
cfg.SelfService.ForgetMe = false
cfg.SelfService.UserRecordChange = true
cfg.Generic.CreateUserWithoutAccessToken = true
//cfg.Generic.UseSeparateAppTables = true
cfg.Policy.MaxUserRetentionPeriod = "1m"
cfg.Policy.MaxAuditRetentionPeriod = "12m"
cfg.Policy.MaxSessionRetentionPeriod = "1h"
cfg.Policy.MaxShareableRecordRetentionPeriod = "1m"
}
e = mainEnv{db, cfg, make(chan struct{})}
rootToken2, err := e.db.getRootXtoken()
if err != nil {
log.Printf("Failed to retrieve root token: %s\n", err)
}
log.Printf("Hashed root token: %s\n", rootToken2)
router = e.setupRouter()
router = e.setupConfRouter(router)
//test1 := &testEnv{e, rootToken, router}
e.dbCleanupDo()
log.Printf("**INIT*DONE***\n")
}

/*
func TestBackupOK(t *testing.T) {
log.Printf("root token: %s\n", rootToken)
Expand Down
42 changes: 42 additions & 0 deletions src/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"log"

"github.com/securitybunker/databunker/src/storage"
)

func init() {
log.Printf("**INIT*TEST*CODE***\n")
testDBFile := storage.CreateTestDB()
db, myRootToken, err := setupDB(&testDBFile, nil, "")
if err != nil {
log.Printf("Init error %s", err.Error())
}
rootToken = myRootToken
var cfg Config
cfile := "../databunker.yaml"
err = readConfFile(&cfg, &cfile)
cfg.SelfService.AppRecordChange = []string{"testapp", "super"}
if err != nil {
cfg.SelfService.ForgetMe = false
cfg.SelfService.UserRecordChange = true
cfg.Generic.CreateUserWithoutAccessToken = true
//cfg.Generic.UseSeparateAppTables = true
cfg.Policy.MaxUserRetentionPeriod = "1m"
cfg.Policy.MaxAuditRetentionPeriod = "12m"
cfg.Policy.MaxSessionRetentionPeriod = "1h"
cfg.Policy.MaxShareableRecordRetentionPeriod = "1m"
}
e = mainEnv{db, cfg, make(chan struct{})}
rootToken2, err := e.db.getRootXtoken()
if err != nil {
log.Printf("Failed to retrieve root token: %s\n", err)
}
log.Printf("Hashed root token: %s\n", rootToken2)
router = e.setupRouter()
router = e.setupConfRouter(router)
//test1 := &testEnv{e, rootToken, router}
e.dbCleanupDo()
log.Printf("**INIT*DONE***\n")
}

0 comments on commit 596b747

Please sign in to comment.