Commit 6a8cdbeb authored by Caro Axel's avatar Caro Axel

US-177: Testing and debug

parent d1fe9083
Pipeline #161 failed with stage
......@@ -3,6 +3,7 @@ package main
import (
"dfss"
"dfss/dfssp/authority"
"dfss/mgdb"
"flag"
"fmt"
"runtime"
......@@ -10,9 +11,13 @@ import (
var (
verbose bool
// Private key and certificate
path, country, org, unit, cn string
keySize, validity int
pid *authority.PlatformID
// MongoDB connection
dbName, dbEnvVarName string
dbManager *mgdb.MongoManager
)
func init() {
......@@ -28,6 +33,9 @@ func init() {
flag.IntVar(&keySize, "keySize", 512, "Encoding size for the private key")
flag.IntVar(&validity, "validity", 21, "Root certificate's validity duration (days)")
flag.StringVar(&dbName, "dbn", "myDatabase", "Name of the mongo database to connect to")
flag.StringVar(&dbEnvVarName, "dbenv", mgdb.DefaultDBUrl, "Name of the environment variable containing the server url in standard MongoDB format")
flag.Usage = func() {
fmt.Println("DFSS platform v" + dfss.Version)
fmt.Println("Users and contracts manager")
......@@ -38,7 +46,7 @@ func init() {
fmt.Println("\nThe commands are:")
fmt.Println(" init [cn, country, keySize, org, path, unit, validity]")
fmt.Println(" create and save the platform's private key and root certificate")
fmt.Println(" start [path]")
fmt.Println(" start [path, dbn, dbenv]")
fmt.Println(" start the platform after loading its private key and root certificate")
fmt.Println(" help print this help")
fmt.Println(" version print dfss client version")
......@@ -67,12 +75,21 @@ func main() {
case "start":
pid, err := authority.Start(path)
if err != nil {
fmt.Println("An error occured during the start operation")
fmt.Println("An error occured during the private key and root certificate retrieval")
fmt.Println(err)
panic(err)
}
// TODO: use pid
_ = pid
dbManager, err := mgdb.NewManager(dbName, dbEnvVarName)
if err != nil {
fmt.Println("An error occured during the connection to Mongo DB")
fmt.Println(err)
panic(err)
}
// TODO: use dbManager
_ = dbManager
default:
flag.Usage()
}
......
......@@ -6,6 +6,8 @@ import (
"os"
)
const DefaultDBUrl = "MGDB_URL"
// errorConnection represents an error to be thrown upon connection
type errorConnection struct {
s string
......
......@@ -19,22 +19,20 @@ type hand struct {
CardTwo card `key:"card_two" bson:"card_two"`
}
const defaultDBUrl = "MGDB_URL"
var collection *MongoCollection
var manager *MongoManager
var err error
func TestMain(m *testing.M) {
// Setup
fmt.Println("Try to connect to : " + os.Getenv(defaultDBUrl))
fmt.Println("Try to connect to : " + os.Getenv(DefaultDBUrl))
db := os.Getenv(defaultDBUrl)
db := os.Getenv(DefaultDBUrl)
if db == "" {
db = "demo"
}
manager, err = NewManager(db, defaultDBUrl)
manager, err = NewManager(db, DefaultDBUrl)
collection = manager.Get("demo")
......@@ -187,7 +185,7 @@ func ExampleMongoManager() {
}
//Initializes a MongoManager for the 'demo' database
manager, err := NewManager("demo", defaultDBUrl)
manager, err := NewManager("demo", DefaultDBUrl)
if err != nil { /* Handle error */
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment