From 596b747204a420dd250aca17bbcaf72dfaad61e2 Mon Sep 17 00:00:00 2001 From: yuli Date: Thu, 3 Oct 2024 22:17:29 +0300 Subject: [PATCH] refactor test code --- src/bunker_test.go | 36 ------------------------------------ src/init_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 src/init_test.go diff --git a/src/bunker_test.go b/src/bunker_test.go index 0f38eda3..9e8a00b1 100644 --- a/src/bunker_test.go +++ b/src/bunker_test.go @@ -11,7 +11,6 @@ import ( uuid "github.com/hashicorp/go-uuid" "github.com/julienschmidt/httprouter" - "github.com/securitybunker/databunker/src/storage" ) var ( @@ -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) diff --git a/src/init_test.go b/src/init_test.go new file mode 100644 index 00000000..30bc3090 --- /dev/null +++ b/src/init_test.go @@ -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") +}