kopia lustrzana https://github.com/reiver/greatape
test(workspace): ✅ add test module
rodzic
224ebd012f
commit
13c8398cb4
|
@ -8,5 +8,6 @@ use (
|
|||
./db
|
||||
./logging
|
||||
./server
|
||||
./tests
|
||||
./utility
|
||||
)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module tests
|
||||
|
||||
go 1.19
|
|
@ -0,0 +1,17 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
resp, err := http.DefaultClient.Get(Root + "/health")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"app/models/repos"
|
||||
"app/routes"
|
||||
"config"
|
||||
"db"
|
||||
"fmt"
|
||||
"logging"
|
||||
"os"
|
||||
"server"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const Root = "http://localhost"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
logger := logging.CreateLogger(logging.StdIOLogger)
|
||||
|
||||
storage := db.CreateStorage(db.SqliteStorage)
|
||||
storage.Connect(config.SQLITE_DB)
|
||||
storage.Migrate(
|
||||
&repos.User{},
|
||||
&repos.IncomingActivity{},
|
||||
&repos.OutgoingActivity{},
|
||||
&repos.Follower{},
|
||||
&repos.Following{},
|
||||
)
|
||||
|
||||
app := server.New()
|
||||
app.SetStorageProvider(storage)
|
||||
app.SetLogger(logger)
|
||||
app.Bind(routes.All...)
|
||||
|
||||
go func() {
|
||||
app.Listen(fmt.Sprintf(":%s", config.PORT))
|
||||
}()
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
Ładowanie…
Reference in New Issue