Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

increase coverage

Guilherme Oenningb6573b191d6a
diff --git a/handlers/status.go b/handlers/status.go
index fddc0f051..7d0af1101 100644
--- a/handlers/status.go
+++ b/handlers/status.go
@@ -9,11 +9,11 @@ import (
)
type statusHandler struct {
- ctx context.WchyContext
+ ctx *context.WchyContext
}
// Status creates a new Status HTTP handler
-func Status(ctx context.WchyContext) gin.HandlerFunc {
+func Status(ctx *context.WchyContext) gin.HandlerFunc {
return statusHandler{ctx: ctx}.get()
}
diff --git a/handlers/status_test.go b/handlers/status_test.go
index 73bf49b8c..f03b60bd7 100644
--- a/handlers/status_test.go
+++ b/handlers/status_test.go
@@ -18,7 +18,7 @@ func (svc inMemoryHealthCheckService) IsDatabaseOnline() bool {
func TestStatusHandler(t *testing.T) {
RegisterTestingT(t)
- ctx := context.WchyContext{
+ ctx := &context.WchyContext{
Health: &inMemoryHealthCheckService{status: false},
Settings: context.WchySettings{
BuildTime: "today",
diff --git a/handlers/tenant.go b/handlers/tenant.go
index 29d733e70..e49544a53 100644
--- a/handlers/tenant.go
+++ b/handlers/tenant.go
@@ -7,11 +7,11 @@ import (
)
type tenantHandlers struct {
- ctx context.WchyContext
+ ctx *context.WchyContext
}
// TenantByDomain creates a new TenantByDomain HTTP handler
-func TenantByDomain(ctx context.WchyContext) gin.HandlerFunc {
+func TenantByDomain(ctx *context.WchyContext) gin.HandlerFunc {
return tenantHandlers{ctx: ctx}.byDomain()
}
diff --git a/handlers/tenant_test.go b/handlers/tenant_test.go
index a1a4aedcd..318c2770e 100644
--- a/handlers/tenant_test.go
+++ b/handlers/tenant_test.go
@@ -23,7 +23,7 @@ func (svc inMemoryTenantService) GetByDomain(domain string) (*models.Tenant, err
return nil, services.ErrNotFound
}
-var ctx context.WchyContext = context.WchyContext{
+var ctx *context.WchyContext = &context.WchyContext{
Tenant: &inMemoryTenantService{tenants: []*models.Tenant{
&models.Tenant{ID: 1, Name: "Orange Inc.", Domain: "orange"},
&models.Tenant{ID: 2, Name: "The Triathlon Shop", Domain: "trishop"},
diff --git a/main.go b/main.go
index 7ba81c644..fc0069350 100644
--- a/main.go
+++ b/main.go
@@ -14,8 +14,7 @@ import (
)
var log = logging.MustGetLogger("main")
-var ctx context.WchyContext
-var settings context.WchySettings
+var ctx *context.WchyContext
var db *sql.DB
var buildtime string
@@ -25,7 +24,7 @@ func init() {
db, _ = sql.Open("postgres", os.Getenv("DATABASE_URL"))
- ctx = context.WchyContext{
+ ctx = &context.WchyContext{
Health: &services.PostgresHealthCheckService{DB: db},
Tenant: &services.PostgresTenantService{DB: db},
Settings: context.WchySettings{
diff --git a/router/router.go b/router/router.go
index 324e6c247..64ac2e367 100644
--- a/router/router.go
+++ b/router/router.go
@@ -13,7 +13,7 @@ import (
"github.com/gin-gonic/gin"
)
-func multiTenant(ctx context.WchyContext) gin.HandlerFunc {
+func multiTenant(ctx *context.WchyContext) gin.HandlerFunc {
return func(c *gin.Context) {
hostname := stripPort(c.Request.Host)
tenant, err := ctx.Tenant.GetByDomain(hostname)
@@ -38,7 +38,7 @@ func stripPort(hostport string) string {
}
// GetMainEngine returns main HTTP engine
-func GetMainEngine(ctx context.WchyContext) *gin.Engine {
+func GetMainEngine(ctx *context.WchyContext) *gin.Engine {
router := gin.New()
if env.IsDevelopment() {
diff --git a/router/router_test.go b/router/router_test.go
new file mode 100644
index 000000000..a1cc2e4e4
--- /dev/null
+++ b/router/router_test.go
@@ -0,0 +1,23 @@
+package router
+
+import (
+ "testing"
+
+ . "github.com/onsi/gomega"
+)
+
+func TestRouter(t *testing.T) {
+ RegisterTestingT(t)
+
+ r := GetMainEngine(nil)
+ Expect(r).ToNot(BeNil())
+}
+
+func TestStripPort(t *testing.T) {
+ RegisterTestingT(t)
+
+ Expect(stripPort("localhost:3000")).To(Equal("localhost"))
+ Expect(stripPort("mypage.com:3000")).To(Equal("mypage.com"))
+ Expect(stripPort("sub.mypage.com:3000")).To(Equal("sub.mypage.com"))
+ Expect(stripPort("mypage.com")).To(Equal("mypage.com"))
+}