Prepare to merge master

This commit is contained in:
Héctor Hurtado
2019-10-08 09:40:51 +02:00
parent 7fdef70e39
commit bb0a283813
2 changed files with 9 additions and 54 deletions
+8 -37
View File
@@ -2,14 +2,8 @@ package server
import ( import (
"fmt" "fmt"
"log"
"net/url" "net/url"
"os"
"strconv" "strconv"
"github.com/BBVA/kapow/server/control"
"github.com/BBVA/kapow/server/data"
"github.com/BBVA/kapow/server/user"
) )
// StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them // StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them
@@ -26,37 +20,14 @@ func StartServer(bindAddr, certfile, keyfile string, interactive bool) error {
return fmt.Errorf("Error extracting port from provided address %s", bindAddr) return fmt.Errorf("Error extracting port from provided address %s", bindAddr)
} }
if certfile != "" { ctrlBindAddr := fmt.Sprintf("%s:%d", userBindAddr.Host, userPort+1)
if _, err := os.Stat(certfile); err != nil { dataBindAddr := fmt.Sprintf("%s:%d", userBindAddr.Host, userPort+2)
if os.IsNotExist(err) {
return fmt.Errorf("Certfile %s does not exist", certfile)
}
}
}
if keyfile != "" { fmt.Printf("User server bind address: %s, Control server bind address: %s, Data server bind address: %s", bindAddr, ctrlBindAddr, dataBindAddr)
if _, err := os.Stat(keyfile); err != nil { //go ctrlServer.Start(traceChannel)
if os.IsNotExist(err) { //go dataServer.Start(traceChannel)
return fmt.Errorf("Keyfile %s does not exist", keyfile) //go ctrlServer.Start(traceChannel)
}
}
}
ctrlPort := userPort + 1 // Wait for ever
dataPort := ctrlPort + 1 select {}
dataServer := data.NewDataServer(userBindAddr.Host(), dataPort, certfile, keyfile)
ctrlServer := control.NewControlServer(userBindAddr.Host(), ctrlPort, certfile, keyfile) // Needs a reference to the user server in order to manage routes
userServer := user.NewUserServer(userBindAddr.Host(), controlServerPort, certfile, keyfile) // Needs a reference to the data server in order to manage handlers
traceChannel := make(chan string)
go ctrlServer.Start(traceChannel)
go dataServer.Start(traceChannel)
go ctrlServer.Start(traceChannel)
// Wait for ever while writing logs
for {
log.Print(<-traceChannel)
}
} }
+1 -17
View File
@@ -3,7 +3,7 @@ package server_test
import ( import (
"testing" "testing"
"github.com/BBVA/kapow/server" "github.com/BBVA/kapow/internal/server"
) )
func TestStartServerWhenInvalidBindAddrReturnsError(t *testing.T) { func TestStartServerWhenInvalidBindAddrReturnsError(t *testing.T) {
@@ -21,19 +21,3 @@ func TestStartServerWhenInvalidPortNumberReturnsError(t *testing.T) {
t.Errorf("Expected error not found") t.Errorf("Expected error not found")
} }
} }
func TestStartServerWhenCertfileDontExistReturnsError(t *testing.T) {
err := server.StartServer("0.0.0.0:8080", "/notExist", "", true)
if err == nil {
t.Errorf("Expected error not found")
}
}
func TestStartServerWhenKeyfileDontExistReturnsError(t *testing.T) {
err := server.StartServer("0.0.0.0:8080", "", "/notExist", true)
if err == nil {
t.Errorf("Expected error not found")
}
}