mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
config: fix typo GolbalConfig -> GlobalConfig
This commit is contained in:
parent
c404c7af5a
commit
2625e16fbe
19 changed files with 109 additions and 98 deletions
|
@ -30,10 +30,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Global configuration
|
// Global configuration
|
||||||
var GolbalConfig *config.Config = nil
|
var GlobalConfig *config.Config = nil
|
||||||
|
|
||||||
func InitConfig() error {
|
func InitConfig() error {
|
||||||
if GolbalConfig != nil {
|
if GlobalConfig != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,25 +128,25 @@ func InitConfig() error {
|
||||||
env := config.NewEnvironment(mappings)
|
env := config.NewEnvironment(mappings)
|
||||||
|
|
||||||
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
|
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
|
||||||
GolbalConfig = config.NewConfig([]config.Provider{defaults, env})
|
GlobalConfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
} else {
|
} else {
|
||||||
yamlFile := config.NewYAMLFile(*configFile)
|
yamlFile := config.NewYAMLFile(*configFile)
|
||||||
GolbalConfig = config.NewConfig([]config.Provider{defaults, yamlFile, env})
|
GlobalConfig = config.NewConfig([]config.Provider{defaults, yamlFile, env})
|
||||||
}
|
}
|
||||||
|
|
||||||
err := GolbalConfig.Load()
|
err := GlobalConfig.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("failed to parse config")
|
log.Fatal("failed to parse config")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := GolbalConfig.String("mode")
|
m, err := GlobalConfig.String("mode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if m != "test" {
|
if m != "test" {
|
||||||
settings, _ := GolbalConfig.Settings()
|
settings, _ := GlobalConfig.Settings()
|
||||||
log.Print("All settings:")
|
log.Print("All settings:")
|
||||||
for key, val := range settings {
|
for key, val := range settings {
|
||||||
// TODO password settings should be excluded!
|
// TODO password settings should be excluded!
|
||||||
|
@ -165,31 +165,31 @@ func ConfigureBackend() (string, string, string, string, string, string, string,
|
||||||
return "", "", "", "", "", "", "", err
|
return "", "", "", "", "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, err := GolbalConfig.String("mode")
|
mode, err := GlobalConfig.String("mode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading mode from global configuration: %v, aborting.", err.Error())
|
log.Printf("Error reading mode from global configuration: %v, aborting.", err.Error())
|
||||||
return "", "", "", "", "", "", "", err
|
return "", "", "", "", "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseHost, err := GolbalConfig.String("base.host")
|
baseHost, err := GlobalConfig.String("base.host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading base.host from global configuration: %v, aborting.", err.Error())
|
log.Printf("Error reading base.host from global configuration: %v, aborting.", err.Error())
|
||||||
return "", "", "", "", "", "", "", err
|
return "", "", "", "", "", "", "", err
|
||||||
}
|
}
|
||||||
basePath, err := GolbalConfig.String("base.path")
|
basePath, err := GlobalConfig.String("base.path")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading base.path from global configuration: %v, aborting.", err.Error())
|
log.Printf("Error reading base.path from global configuration: %v, aborting.", err.Error())
|
||||||
return "", "", "", "", "", "", "", err
|
return "", "", "", "", "", "", "", err
|
||||||
}
|
}
|
||||||
port, err := GolbalConfig.String("port")
|
port, err := GlobalConfig.String("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading port from global configuration: %v, aborting.", err.Error())
|
log.Printf("Error reading port from global configuration: %v, aborting.", err.Error())
|
||||||
return "", "", "", "", "", "", "", err
|
return "", "", "", "", "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
AMQPhost, _ := GolbalConfig.String("amqp.host")
|
AMQPhost, _ := GlobalConfig.String("amqp.host")
|
||||||
AMQPuser, _ := GolbalConfig.String("amqp.user")
|
AMQPuser, _ := GlobalConfig.String("amqp.user")
|
||||||
AMQPpass, _ := GolbalConfig.String("amqp.pass")
|
AMQPpass, _ := GlobalConfig.String("amqp.pass")
|
||||||
|
|
||||||
return mode, baseHost, basePath, port, AMQPhost, AMQPuser, AMQPpass, nil
|
return mode, baseHost, basePath, port, AMQPhost, AMQPuser, AMQPpass, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,11 @@ package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/zpatrick/go-config"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/zpatrick/go-config"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -52,33 +53,33 @@ func TestInitDB(t *testing.T) {
|
||||||
|
|
||||||
err = InitDB(ownconfig)
|
err = InitDB(ownconfig)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
dbname, err := configuration.GolbalConfig.String("db.name")
|
dbname, err := configuration.GlobalConfig.String("db.name")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
static["db.name"] = dbname
|
static["db.name"] = dbname
|
||||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
err = InitDB(ownconfig)
|
err = InitDB(ownconfig)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
dbhost, err := configuration.GolbalConfig.String("db.host")
|
dbhost, err := configuration.GlobalConfig.String("db.host")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
static["db.host"] = dbhost
|
static["db.host"] = dbhost
|
||||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
err = InitDB(ownconfig)
|
err = InitDB(ownconfig)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
dbuser, err := configuration.GolbalConfig.String("db.user")
|
dbuser, err := configuration.GlobalConfig.String("db.user")
|
||||||
static["db.user"] = dbuser
|
static["db.user"] = dbuser
|
||||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
err = InitDB(ownconfig)
|
err = InitDB(ownconfig)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
dbpass, err := configuration.GolbalConfig.String("db.pass")
|
dbpass, err := configuration.GlobalConfig.String("db.pass")
|
||||||
static["db.pass"] = dbpass
|
static["db.pass"] = dbpass
|
||||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
err = InitDB(ownconfig)
|
err = InitDB(ownconfig)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
dbssl, err := configuration.GolbalConfig.String("db.ssl")
|
dbssl, err := configuration.GlobalConfig.String("db.ssl")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
static["db.ssl"] = dbssl
|
static["db.ssl"] = dbssl
|
||||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||||
|
|
|
@ -23,17 +23,18 @@ package component_configuration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -146,7 +147,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -31,9 +35,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -80,7 +81,7 @@ func TestMain(m *testing.M) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (f *File) Register(fileHeader *multipart.FileHeader, scenarioID uint) error
|
||||||
}
|
}
|
||||||
defer fileContent.Close()
|
defer fileContent.Close()
|
||||||
|
|
||||||
bucket, err := configuration.GolbalConfig.String("s3.bucket")
|
bucket, err := configuration.GlobalConfig.String("s3.bucket")
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
f.FileData, err = ioutil.ReadAll(fileContent)
|
f.FileData, err = ioutil.ReadAll(fileContent)
|
||||||
f.Key = ""
|
f.Key = ""
|
||||||
|
@ -157,7 +157,7 @@ func (f *File) update(fileHeader *multipart.FileHeader) error {
|
||||||
}
|
}
|
||||||
defer fileContent.Close()
|
defer fileContent.Close()
|
||||||
|
|
||||||
bucket, err := configuration.GolbalConfig.String("s3.bucket")
|
bucket, err := configuration.GlobalConfig.String("s3.bucket")
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
f.FileData, err = ioutil.ReadAll(fileContent)
|
f.FileData, err = ioutil.ReadAll(fileContent)
|
||||||
f.Key = ""
|
f.Key = ""
|
||||||
|
|
|
@ -40,7 +40,7 @@ var s3Session *session.Session = nil
|
||||||
|
|
||||||
func getS3Session() (*session.Session, string, error) {
|
func getS3Session() (*session.Session, string, error) {
|
||||||
|
|
||||||
bucket, err := configuration.GolbalConfig.String("s3.bucket")
|
bucket, err := configuration.GlobalConfig.String("s3.bucket")
|
||||||
if err != nil || bucket == "" {
|
if err != nil || bucket == "" {
|
||||||
return nil, "", fmt.Errorf("no S3 bucket configured: %s", err)
|
return nil, "", fmt.Errorf("no S3 bucket configured: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,10 @@ func getS3Session() (*session.Session, string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createS3Session() (*session.Session, error) {
|
func createS3Session() (*session.Session, error) {
|
||||||
endpoint, err := configuration.GolbalConfig.String("s3.endpoint")
|
endpoint, err := configuration.GlobalConfig.String("s3.endpoint")
|
||||||
region, err := configuration.GolbalConfig.String("s3.region")
|
region, err := configuration.GlobalConfig.String("s3.region")
|
||||||
pathStyle, err := configuration.GolbalConfig.Bool("s3.pathstyle")
|
pathStyle, err := configuration.GlobalConfig.Bool("s3.pathstyle")
|
||||||
nossl, err := configuration.GolbalConfig.Bool("s3.nossl")
|
nossl, err := configuration.GlobalConfig.Bool("s3.nossl")
|
||||||
|
|
||||||
sess, err := session.NewSession(
|
sess, err := session.NewSession(
|
||||||
&aws.Config{
|
&aws.Config{
|
||||||
|
|
|
@ -24,6 +24,14 @@ package file
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -32,13 +40,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -83,7 +84,7 @@ func TestMain(m *testing.M) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,15 @@
|
||||||
package healthz
|
package healthz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHealthzEndpoint(r *gin.RouterGroup) {
|
func RegisterHealthzEndpoint(r *gin.RouterGroup) {
|
||||||
|
@ -55,7 +56,7 @@ func getHealth(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if connection to AMQP broker is alive if backend was started with AMQP client
|
// check if connection to AMQP broker is alive if backend was started with AMQP client
|
||||||
url, err := configuration.GolbalConfig.String("amqp.host")
|
url, err := configuration.GlobalConfig.String("amqp.host")
|
||||||
if err != nil && strings.Contains(err.Error(), "Required setting 'amqp.host' not set") {
|
if err != nil && strings.Contains(err.Error(), "Required setting 'amqp.host' not set") {
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,15 +22,16 @@
|
||||||
package healthz
|
package healthz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -40,7 +41,7 @@ func TestHealthz(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// connect DB
|
// connect DB
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer database.DBpool.Close()
|
defer database.DBpool.Close()
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ func TestHealthz(t *testing.T) {
|
||||||
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// reconnect DB
|
// reconnect DB
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer database.DBpool.Close()
|
defer database.DBpool.Close()
|
||||||
|
|
||||||
|
@ -68,11 +69,11 @@ func TestHealthz(t *testing.T) {
|
||||||
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
|
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
|
||||||
host, err := configuration.GolbalConfig.String("amqp.host")
|
host, err := configuration.GlobalConfig.String("amqp.host")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := configuration.GolbalConfig.String("amqp.user")
|
user, err := configuration.GlobalConfig.String("amqp.user")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
pass, err := configuration.GolbalConfig.String("amqp.pass")
|
pass, err := configuration.GlobalConfig.String("amqp.pass")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
||||||
|
|
|
@ -24,15 +24,16 @@ package infrastructure_component
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/streadway/amqp"
|
"github.com/streadway/amqp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
@ -126,9 +127,9 @@ func TestAddICAsAdmin(t *testing.T) {
|
||||||
|
|
||||||
// connect AMQP client
|
// connect AMQP client
|
||||||
// Make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set
|
// Make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set
|
||||||
host, err := configuration.GolbalConfig.String("amqp.host")
|
host, err := configuration.GlobalConfig.String("amqp.host")
|
||||||
user, err := configuration.GolbalConfig.String("amqp.user")
|
user, err := configuration.GlobalConfig.String("amqp.user")
|
||||||
pass, err := configuration.GolbalConfig.String("amqp.pass")
|
pass, err := configuration.GlobalConfig.String("amqp.pass")
|
||||||
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
||||||
|
|
||||||
// AMQP Connection startup is tested here
|
// AMQP Connection startup is tested here
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@ func TestMain(m *testing.M) {
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
||||||
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
|
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
|
||||||
host, err := configuration.GolbalConfig.String("amqp.host")
|
host, err := configuration.GlobalConfig.String("amqp.host")
|
||||||
user, err := configuration.GolbalConfig.String("amqp.user")
|
user, err := configuration.GlobalConfig.String("amqp.user")
|
||||||
pass, err := configuration.GolbalConfig.String("amqp.pass")
|
pass, err := configuration.GlobalConfig.String("amqp.pass")
|
||||||
|
|
||||||
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
amqpURI := "amqp://" + user + ":" + pass + "@" + host
|
||||||
|
|
||||||
|
@ -76,6 +76,6 @@ func TestAddTestData(t *testing.T) {
|
||||||
panic(t)
|
panic(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := AddTestData(configuration.GolbalConfig, router)
|
resp, err := AddTestData(configuration.GlobalConfig, router)
|
||||||
assert.NoError(t, err, "Response body: %v", resp)
|
assert.NoError(t, err, "Response body: %v", resp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,14 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -35,13 +43,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -98,7 +99,7 @@ func TestMain(m *testing.M) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ package scenario
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -30,8 +33,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -56,7 +57,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,19 @@ package signal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -141,7 +142,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ func authenticate(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expiresStr, err := configuration.GolbalConfig.String("jwt.expires-after")
|
expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnauthorizedError(c, "Backend configuration error")
|
helper.UnauthorizedError(c, "Backend configuration error")
|
||||||
return
|
return
|
||||||
|
@ -100,7 +100,7 @@ func authenticate(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
secret, err := configuration.GolbalConfig.String("jwt.secret")
|
secret, err := configuration.GlobalConfig.String("jwt.secret")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnauthorizedError(c, "Backend configuration error")
|
helper.UnauthorizedError(c, "Backend configuration error")
|
||||||
return
|
return
|
||||||
|
|
|
@ -68,7 +68,7 @@ func Authentication(unauthorized bool) gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// return secret in byte format
|
// return secret in byte format
|
||||||
secret, _ := configuration.GolbalConfig.String("jwt.secret")
|
secret, _ := configuration.GlobalConfig.String("jwt.secret")
|
||||||
return []byte(secret), nil
|
return []byte(secret), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ package widget
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -32,8 +35,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -105,7 +106,7 @@ func TestMain(m *testing.M) {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(m)
|
panic(m)
|
||||||
}
|
}
|
||||||
|
|
6
start.go
6
start.go
|
@ -30,7 +30,7 @@ import (
|
||||||
apidocs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
apidocs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/zpatrick/go-config"
|
"github.com/zpatrick/go-config"
|
||||||
)
|
)
|
||||||
|
@ -79,7 +79,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//init database
|
//init database
|
||||||
err = database.InitDB(configuration.GolbalConfig)
|
err = database.InitDB(configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error during initialization of database: %v, aborting.", err.Error())
|
log.Printf("Error during initialization of database: %v, aborting.", err.Error())
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -107,7 +107,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add data to DB (if any)
|
// add data to DB (if any)
|
||||||
err = addData(r, configuration.GolbalConfig)
|
err = addData(r, configuration.GlobalConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue