feat: Added test cases for s3 api router, server creation and some controllers

This commit is contained in:
jonaustin09
2023-05-19 00:28:07 +04:00
parent 9245aba641
commit a265cd5344
3 changed files with 67 additions and 8 deletions

View File

@@ -5,20 +5,31 @@ import (
"testing"
"github.com/gofiber/fiber/v2"
"github.com/valyala/fasthttp"
"github.com/versity/scoutgw/backend"
"github.com/versity/scoutgw/s3err"
)
func TestNew(t *testing.T) {
type args struct {
be backend.Backend
}
be := backend.BackendUnsupported{}
tests := []struct {
name string
args args
want S3ApiController
}{
// TODO: Add test cases.
{
name: "Initialize S3 api controller",
args: args{
be: be,
},
want: S3ApiController{
be: be,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -33,13 +44,25 @@ func TestS3ApiController_ListBuckets(t *testing.T) {
type args struct {
ctx *fiber.Ctx
}
app := fiber.New()
tests := []struct {
name string
c S3ApiController
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "Returns successful response",
c: S3ApiController{
be: backend.BackendUnsupported{},
},
args: args{
ctx: app.AcquireCtx(&fasthttp.RequestCtx{}),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -264,7 +287,7 @@ func Test_responce(t *testing.T) {
type args struct {
ctx *fiber.Ctx
resp any
code s3err.ErrorCode
err error
}
tests := []struct {
name string
@@ -275,7 +298,7 @@ func Test_responce(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := responce(tt.args.ctx, tt.args.resp, tt.args.code); (err != nil) != tt.wantErr {
if err := responce(tt.args.ctx, tt.args.resp, tt.args.err); (err != nil) != tt.wantErr {
t.Errorf("responce() error = %v, wantErr %v", err, tt.wantErr)
}
})

View File

@@ -17,7 +17,14 @@ func TestS3ApiRouter_Init(t *testing.T) {
sa *S3ApiRouter
args args
}{
// TODO: Add test cases.
{
name: "Initialize S3 api router",
sa: &S3ApiRouter{},
args: args{
app: fiber.New(),
be: backend.BackendUnsupported{},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View File

@@ -14,13 +14,33 @@ func TestNew(t *testing.T) {
be backend.Backend
port string
}
app := fiber.New()
be := backend.BackendUnsupported{}
router := S3ApiRouter{}
port := ":7070"
tests := []struct {
name string
args args
wantS3ApiServer *S3ApiServer
wantErr bool
}{
// TODO: Add test cases.
{
name: "Create S3 api server",
args: args{
app: app,
be: be,
port: port,
},
wantS3ApiServer: &S3ApiServer{
app: app,
port: port,
router: &router,
backend: be,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -42,7 +62,16 @@ func TestS3ApiServer_Serve(t *testing.T) {
sa *S3ApiServer
wantErr bool
}{
// TODO: Add test cases.
{
name: "Return error when serving S3 api server with invalid address",
wantErr: true,
sa: &S3ApiServer{
app: fiber.New(),
backend: backend.BackendUnsupported{},
port: "Wrong address",
router: &S3ApiRouter{},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {