Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Add test (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuka authored Jun 11, 2020
1 parent 1931898 commit 6b64939
Show file tree
Hide file tree
Showing 3 changed files with 921 additions and 0 deletions.
38 changes: 38 additions & 0 deletions server/grpc_gateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package server

import (
"fmt"
"testing"
"time"

"github.com/mosuka/blast/log"
"github.com/mosuka/blast/util"
)

func Test_GRPCGateway_Start_Stop(t *testing.T) {
httpAddress := fmt.Sprintf(":%d", util.TmpPort())
grpcAddress := fmt.Sprintf(":%d", util.TmpPort())
certificateFile := ""
KeyFile := ""
commonName := ""
corsAllowedMethods := make([]string, 0)
corsAllowedOrigins := make([]string, 0)
corsAllowedHeaders := make([]string, 0)
logger := log.NewLogger("WARN", "", 500, 3, 30, false)

grpcGateway, err := NewGRPCGateway(httpAddress, grpcAddress, certificateFile, KeyFile, commonName, corsAllowedMethods, corsAllowedOrigins, corsAllowedHeaders, logger)
if err != nil {
t.Fatalf("%v", err)
}
defer func() {
if err := grpcGateway.Stop(); err != nil {
t.Fatalf("%v", err)
}
}()

if err := grpcGateway.Start(); err != nil {
t.Fatalf("%v", err)
}

time.Sleep(3 * time.Second)
}
72 changes: 72 additions & 0 deletions server/grpc_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package server

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/mosuka/blast/log"
"github.com/mosuka/blast/mapping"
"github.com/mosuka/blast/util"
)

func Test_GRPCServer_Start_Stop(t *testing.T) {
curDir, err := os.Getwd()
if err != nil {
t.Fatalf("%v", err)
}

tmpDir := util.TmpDir()
defer func() {
_ = os.RemoveAll(tmpDir)
}()

logger := log.NewLogger("WARN", "", 500, 3, 30, false)

// Raft server
rafAddress := fmt.Sprintf(":%d", util.TmpPort())
dir := util.TmpDir()
defer func() {
_ = os.RemoveAll(dir)
}()
indexMapping, err := mapping.NewIndexMappingFromFile(filepath.Join(curDir, "../examples/example_mapping.json"))
if err != nil {
t.Fatalf("%v", err)
}
raftServer, err := NewRaftServer("node1", rafAddress, dir, indexMapping, true, logger)
if err != nil {
t.Fatalf("%v", err)
}
defer func() {
if err := raftServer.Stop(); err != nil {
t.Fatalf("%v", err)
}
}()
if err := raftServer.Start(); err != nil {
t.Fatalf("%v", err)
}

// gRPC server
grpcAddress := fmt.Sprintf(":%d", util.TmpPort())
certificateFile := ""
keyFile := ""
commonName := ""

grpcServer, err := NewGRPCServer(grpcAddress, raftServer, certificateFile, keyFile, commonName, logger)
if err != nil {
t.Fatalf("%v", err)
}
defer func() {
if err := grpcServer.Stop(); err != nil {
t.Fatalf("%v", err)
}
}()

if err := grpcServer.Start(); err != nil {
t.Fatalf("%v", err)
}

time.Sleep(3 * time.Second)
}
Loading

0 comments on commit 6b64939

Please sign in to comment.