Skip to content

Commit

Permalink
chore: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Oct 2, 2021
1 parent 1619482 commit 6997a36
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 93 deletions.
74 changes: 0 additions & 74 deletions core/component/tracing.go

This file was deleted.

193 changes: 188 additions & 5 deletions core/controller/basic_auth_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"

Expand All @@ -34,7 +35,7 @@ func TestUnitBasicAuthDataEndpoints(t *testing.T) {

defer database.Close()

database.CreateAuthMethod(&model.AuthMethod{
result := database.CreateAuthMethod(&model.AuthMethod{
Name: "customers_public",
Description: "Public API",
Type: "any_authentication",
Expand All @@ -53,31 +54,213 @@ func TestUnitBasicAuthDataEndpoints(t *testing.T) {

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusBadRequest)
g.Assert(strings.Contains(rec.Body.String(), "message=BadReques")).Equal(true)
g.Assert(strings.Contains(rec.Body.String(), "message=BadRequest")).Equal(true)
})
})

g.Describe("#GetBasicAuthData", func() {
g.Describe("#CreateBasicAuthData.Failure", func() {
g.It("It should satisfy all provided test cases", func() {
e := echo.New()

item := &model.BasicAuthData{
Name: "j.doe",
Username: "admin",
Password: "admin",
Meta: "",
}

body, _ := item.ConvertToJSON()

req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", strings.NewReader(body))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/apigw/api/v1/auth/basic")

err := CreateBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusBadRequest)
g.Assert(strings.Contains(rec.Body.String(), "message=BadRequest")).Equal(true)
})
})

g.Describe("#CreateBasicAuthData.Success", func() {
g.It("It should satisfy all provided test cases", func() {
e := echo.New()

item := &model.BasicAuthData{
Name: "j.doe",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
}

body, _ := item.ConvertToJSON()

req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", strings.NewReader(body))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/apigw/api/v1/auth/basic")

err := CreateBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusCreated)
})
})

g.Describe("#GetBasicAuthData.Found", func() {
g.It("It should satisfy all provided test cases", func() {
item := database.CreateBasicAuthData(&model.BasicAuthData{
Name: "j.doe",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
})

e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetParamNames("id")
c.SetParamValues(strconv.Itoa(item.ID))
c.SetPath("/apigw/api/v1/auth/basic")

err := GetBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusOK)
g.Assert(strings.Contains(rec.Body.String(), item.Name)).Equal(true)
})
})

g.Describe("#GetBasicAuthItems", func() {
g.It("It should satisfy all provided test cases", func() {
item := database.CreateBasicAuthData(&model.BasicAuthData{
Name: "j.doe2",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
})

e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/apigw/api/v1/auth/basic")

err := GetBasicAuthItems(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusOK)
g.Assert(strings.Contains(rec.Body.String(), item.Name)).Equal(true)
})
})

g.Describe("#DeleteBasicAuthData.Success", func() {
g.It("It should satisfy all provided test cases", func() {
item := database.CreateBasicAuthData(&model.BasicAuthData{
Name: "j.doe",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
})

e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetParamNames("id")
c.SetParamValues(strconv.Itoa(item.ID))
c.SetPath("/apigw/api/v1/auth/basic")

err := DeleteBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusNoContent)
})
})

g.Describe("#DeleteBasicAuthData", func() {
g.Describe("#DeleteBasicAuthData.NotFound", func() {
g.It("It should satisfy all provided test cases", func() {
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetParamNames("id")
c.SetParamValues("22222")
c.SetPath("/apigw/api/v1/auth/basic")

err := DeleteBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusNotFound)
})
})

g.Describe("#UpdateBasicAuthData", func() {
g.Describe("#UpdateBasicAuthData.Updated", func() {
g.It("It should satisfy all provided test cases", func() {
item1 := database.CreateBasicAuthData(&model.BasicAuthData{
Name: "j.doe01",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
})

item2 := &model.BasicAuthData{
Name: "j.doe02",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
}

body, _ := item2.ConvertToJSON()

e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", strings.NewReader(body))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetParamNames("id")
c.SetParamValues(strconv.Itoa(item1.ID))
c.SetPath("/apigw/api/v1/auth/basic")

err := UpdateBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusOK)
})
})

g.Describe("#UpdateBasicAuthData.NotFound", func() {
g.It("It should satisfy all provided test cases", func() {
item := &model.BasicAuthData{
Name: "j.doe02",
Username: "admin",
Password: "admin",
Meta: "",
AuthMethodID: result.ID,
}

body, _ := item.ConvertToJSON()

e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/apigw/api/v1/auth/basic", strings.NewReader(body))
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetParamNames("id")
c.SetParamValues("4444")
c.SetPath("/apigw/api/v1/auth/basic")

err := UpdateBasicAuthData(c, &GlobalContext{Database: database})

g.Assert(err).Equal(nil)
g.Assert(rec.Code).Equal(http.StatusNotFound)
})
})
}
9 changes: 5 additions & 4 deletions core/controller/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (

// Me controller
func Me(c echo.Context, _ *GlobalContext) error {
log.WithFields(log.Fields{
"status": "ok",
}).Info(`Create auth method`)
log.Info(`Get access status and permissions`)

return c.JSON(http.StatusOK, map[string]interface{}{
"status": "ok",
"id": "1",
"type": "ok",
"authMethod": "",
"services": "",
})
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ require (
github.com/jinzhu/gorm v1.9.16
github.com/labstack/echo-contrib v0.11.0
github.com/labstack/echo/v4 v4.6.1
github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.11.0
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/uber/jaeger-client-go v2.29.1+incompatible
gopkg.in/yaml.v2 v2.4.0
)
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I=
github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -405,7 +404,6 @@ github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
Expand All @@ -423,7 +421,6 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
Expand Down Expand Up @@ -503,7 +500,6 @@ github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -516,9 +512,6 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-client-go v2.29.1+incompatible h1:R9ec3zO3sGpzs0abd43Y+fBZRJ9uiH6lXyR/+u6brW4=
github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.0+incompatible h1:fY7QsGQWiCt8pajv4r7JEvmATdCVaWxXbjwyYwsNaLQ=
github.com/uber/jaeger-lib v2.4.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
Expand Down Expand Up @@ -550,7 +543,6 @@ go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
Expand Down

0 comments on commit 6997a36

Please sign in to comment.