test: refactor and add submit test
This commit is contained in:
parent
c265da52a1
commit
8f570f99db
|
@ -26,8 +26,9 @@ func New() *fiber.App {
|
||||||
})
|
})
|
||||||
|
|
||||||
err := sentry.Init(sentry.ClientOptions{
|
err := sentry.Init(sentry.ClientOptions{
|
||||||
Dsn: os.Getenv("SENTRY_DSN"),
|
Dsn: os.Getenv("SENTRY_DSN"),
|
||||||
Environment: os.Getenv("ENV"),
|
Environment: os.Getenv("ENV"),
|
||||||
|
AttachStacktrace: true,
|
||||||
// Enable printing of SDK debug messages.
|
// Enable printing of SDK debug messages.
|
||||||
// Useful when getting started or trying to figure something out.
|
// Useful when getting started or trying to figure something out.
|
||||||
Debug: true,
|
Debug: true,
|
||||||
|
@ -58,6 +59,7 @@ func New() *fiber.App {
|
||||||
|
|
||||||
routes.Health(app)
|
routes.Health(app)
|
||||||
routes.Joke(app)
|
routes.Joke(app)
|
||||||
|
routes.Submit(app)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ func GetAllJSONJokes(db *pgxpool.Pool) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer results.Close()
|
||||||
|
|
||||||
err = pgxscan.ScanAll(&jokes, results)
|
err = pgxscan.ScanAll(&jokes, results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -9,49 +9,64 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/jackc/pgx/v4/pgxpool"
|
||||||
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db = database.New()
|
var db *pgxpool.Pool = database.New()
|
||||||
var jokesData = []interface{}{1, "https://via.placeholder.com/300/06f/fff.png", 1, 2, "https://via.placeholder.com/300/07f/fff.png", 1, 3, "https://via.placeholder.com/300/08f/fff.png", 1}
|
var jokesData = []interface{}{1, "https://via.placeholder.com/300/06f/fff.png", 1, 2, "https://via.placeholder.com/300/07f/fff.png", 1, 3, "https://via.placeholder.com/300/08f/fff.png", 1}
|
||||||
|
var app *fiber.App = v1.New()
|
||||||
|
|
||||||
func cleanup() {
|
func cleanup() {
|
||||||
_, err := db.Query(context.Background(), "DROP TABLE \"jokesbapak2\"")
|
j, err := db.Query(context.Background(), "DROP TABLE \"jokesbapak2\"")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
_, err = db.Query(context.Background(), "DROP TABLE \"administrators\"")
|
a, err := db.Query(context.Background(), "DROP TABLE \"administrators\"")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer j.Close()
|
||||||
|
defer a.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup() error {
|
||||||
|
err := database.Setup()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a, err := db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", "not the real one", time.Now().Format(time.RFC3339))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
j, err := db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer a.Close()
|
||||||
|
defer j.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealth(t *testing.T) {
|
func TestHealth(t *testing.T) {
|
||||||
err := database.Setup()
|
err := setup()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", "not the real one", time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
defer cleanup()
|
||||||
|
|
||||||
app := v1.New()
|
req, _ := http.NewRequest("GET", "/health", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
t.Run("Health - should return 200", func(t *testing.T) {
|
assert.Equalf(t, false, err != nil, "health")
|
||||||
req, _ := http.NewRequest("GET", "/health", nil)
|
assert.Equalf(t, 200, res.StatusCode, "health")
|
||||||
res, err := app.Test(req, -1)
|
assert.NotEqualf(t, 0, res.ContentLength, "health")
|
||||||
|
_, err = ioutil.ReadAll(res.Body)
|
||||||
assert.Equalf(t, false, err != nil, "health")
|
assert.Nilf(t, err, "health")
|
||||||
assert.Equalf(t, 200, res.StatusCode, "health")
|
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "health")
|
|
||||||
_, err = ioutil.ReadAll(res.Body)
|
|
||||||
assert.Nilf(t, err, "health")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,13 @@ func AddNewJoke(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement solution if the link provided already exists.
|
// TODO: Implement solution if the link provided already exists.
|
||||||
_, err = handler.Db.Query(context.Background(), sql, args...)
|
r, err := handler.Db.Query(context.Background(), sql, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,62 +1,55 @@
|
||||||
package joke_test
|
package joke_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
v1 "jokes-bapak2-api/app/v1"
|
|
||||||
"jokes-bapak2-api/app/v1/handler"
|
|
||||||
"jokes-bapak2-api/app/v1/platform/database"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddNewJoke(t *testing.T) {
|
func TestAddNewJoke_201(t *testing.T) {
|
||||||
// t.SkipNow()
|
t.SkipNow()
|
||||||
err := database.Setup()
|
err := setup()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
hashedToken := "$argon2id$v=19$m=65536,t=16,p=4$48beb241490caa57fbca8e63df1e1b5fba8934baf78205ee775f96a85f45b889$e6dfca3f69adbe7653dbb353f366d741a3640313c45e33eabaca0c217c16417de80d70ac67f217c9ca46634b0abaad5f4ea2b064caa44ce218fb110b4cba9d36"
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", hashedToken, time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
defer cleanup()
|
||||||
|
|
||||||
app := v1.New()
|
reqBody := strings.NewReader("{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
|
req, _ := http.NewRequest("PUT", "/", reqBody)
|
||||||
t.Run("Add - should return 201", func(t *testing.T) {
|
req.Header.Set("content-type", "application/json")
|
||||||
reqBody := strings.NewReader("{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\",\"key\":\"very secure\",\"token\":\"password\"}")
|
req.Header.Add("accept", "application/json")
|
||||||
req, _ := http.NewRequest("PUT", "/", reqBody)
|
res, err := app.Test(req, -1)
|
||||||
req.Header.Set("content-type", "application/json")
|
|
||||||
req.Header.Add("accept", "application/json")
|
|
||||||
res, err := app.Test(req, -1)
|
|
||||||
|
|
||||||
assert.Equalf(t, false, err != nil, "joke add")
|
|
||||||
assert.Equalf(t, 201, res.StatusCode, "joke add")
|
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke add")
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
|
||||||
assert.Nilf(t, err, "joke add")
|
|
||||||
assert.Equalf(t, "{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\"}", string(body), "joke add")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Add - should not be a valid image", func(t *testing.T) {
|
|
||||||
reqBody := strings.NewReader("{\"link\":\"https://google.com/\",\"key\":\"very secure\",\"token\":\"password\"}")
|
|
||||||
req, _ := http.NewRequest("PUT", "/", reqBody)
|
|
||||||
req.Header.Set("content-type", "application/json")
|
|
||||||
req.Header.Add("accept", "application/json")
|
|
||||||
res, err := app.Test(req, -1)
|
|
||||||
|
|
||||||
assert.Equalf(t, false, err != nil, "joke add")
|
|
||||||
assert.Equalf(t, 400, res.StatusCode, "joke add")
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
|
||||||
assert.Nilf(t, err, "joke add")
|
|
||||||
assert.Equalf(t, "{\"error\":\"URL provided is not a valid image\"}", string(body), "joke add")
|
|
||||||
})
|
|
||||||
|
|
||||||
|
assert.Equalf(t, false, err != nil, "joke add")
|
||||||
|
assert.Equalf(t, 201, res.StatusCode, "joke add")
|
||||||
|
assert.NotEqualf(t, 0, res.ContentLength, "joke add")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "joke add")
|
||||||
|
assert.Equalf(t, "{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\"}", string(body), "joke add")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddNewJoke_NotValidImage(t *testing.T) {
|
||||||
|
t.SkipNow()
|
||||||
|
err := setup()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
reqBody := strings.NewReader("{\"link\":\"https://google.com/\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
|
req, _ := http.NewRequest("PUT", "/", reqBody)
|
||||||
|
req.Header.Set("content-type", "application/json")
|
||||||
|
req.Header.Add("accept", "application/json")
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
|
assert.Equalf(t, false, err != nil, "joke add")
|
||||||
|
assert.Equalf(t, 400, res.StatusCode, "joke add")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "joke add")
|
||||||
|
assert.Equalf(t, "{\"error\":\"URL provided is not a valid image\"}", string(body), "joke add")
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,13 @@ func DeleteJoke(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = handler.Db.Query(context.Background(), sql, args...)
|
r, err := handler.Db.Query(context.Background(), sql, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,64 +1,52 @@
|
||||||
package joke_test
|
package joke_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
v1 "jokes-bapak2-api/app/v1"
|
|
||||||
"jokes-bapak2-api/app/v1/handler"
|
|
||||||
"jokes-bapak2-api/app/v1/platform/database"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeleteJoke(t *testing.T) {
|
func TestDeleteJoke_200(t *testing.T) {
|
||||||
// TODO: Remove this line below, make this test works
|
// TODO: Remove this line below, make this test works
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
|
err := setup()
|
||||||
err := database.Setup()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
hashedToken := "$argon2id$v=19$m=65536,t=16,p=4$48beb241490caa57fbca8e63df1e1b5fba8934baf78205ee775f96a85f45b889$e6dfca3f69adbe7653dbb353f366d741a3640313c45e33eabaca0c217c16417de80d70ac67f217c9ca46634b0abaad5f4ea2b064caa44ce218fb110b4cba9d36"
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", hashedToken, time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
defer cleanup()
|
||||||
|
|
||||||
app := v1.New()
|
reqBody := strings.NewReader("{\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
|
req, _ := http.NewRequest("DELETE", "/id/1", reqBody)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
t.Run("Delete - should return 200", func(t *testing.T) {
|
assert.Equalf(t, false, err != nil, "joke delete")
|
||||||
reqBody := strings.NewReader("{\"key\":\"very secure\",\"token\":\"password\"}")
|
assert.Equalf(t, 200, res.StatusCode, "joke delete")
|
||||||
req, _ := http.NewRequest("DELETE", "/id/1", reqBody)
|
assert.NotEqualf(t, 0, res.ContentLength, "joke delete")
|
||||||
res, err := app.Test(req, -1)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "joke delete")
|
||||||
assert.Equalf(t, false, err != nil, "joke delete")
|
assert.Equalf(t, "{\"message\":\"specified joke id has been deleted\"}", string(body), "joke delete")
|
||||||
assert.Equalf(t, 200, res.StatusCode, "joke delete")
|
}
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke delete")
|
func TestDeleteJoke_NotExists(t *testing.T) {
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
t.SkipNow()
|
||||||
assert.Nilf(t, err, "joke delete")
|
err := setup()
|
||||||
assert.Equalf(t, "{\"message\":\"specified joke id has been deleted\"}", string(body), "joke delete")
|
if err != nil {
|
||||||
})
|
t.Fatal(err)
|
||||||
|
}
|
||||||
t.Run("Delete - id doesn't exists", func(t *testing.T) {
|
|
||||||
reqBody := strings.NewReader("{\"key\":\"very secure\",\"token\":\"password\"}")
|
defer cleanup()
|
||||||
req, _ := http.NewRequest("DELETE", "/id/100", reqBody)
|
|
||||||
res, err := app.Test(req, -1)
|
reqBody := strings.NewReader("{\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
|
req, _ := http.NewRequest("DELETE", "/id/100", reqBody)
|
||||||
assert.Equalf(t, false, err != nil, "joke delete")
|
res, err := app.Test(req, -1)
|
||||||
assert.Equalf(t, 406, res.StatusCode, "joke delete")
|
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke delete")
|
assert.Equalf(t, false, err != nil, "joke delete")
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
assert.Equalf(t, 406, res.StatusCode, "joke delete")
|
||||||
assert.Nilf(t, err, "joke delete")
|
assert.NotEqualf(t, 0, res.ContentLength, "joke delete")
|
||||||
assert.Equalf(t, "{\"message\":\"specified joke id does not exists\"}", string(body), "joke delete")
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
})
|
assert.Nilf(t, err, "joke delete")
|
||||||
|
assert.Equalf(t, "{\"message\":\"specified joke id does not exists\"}", string(body), "joke delete")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,85 +10,125 @@ import (
|
||||||
v1 "jokes-bapak2-api/app/v1"
|
v1 "jokes-bapak2-api/app/v1"
|
||||||
"jokes-bapak2-api/app/v1/platform/database"
|
"jokes-bapak2-api/app/v1/platform/database"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/jackc/pgx/v4/pgxpool"
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db = database.New()
|
var db *pgxpool.Pool = database.New()
|
||||||
var jokesData = []interface{}{1, "https://via.placeholder.com/300/06f/fff.png", 1, 2, "https://via.placeholder.com/300/07f/fff.png", 1, 3, "https://via.placeholder.com/300/08f/fff.png", 1}
|
var jokesData = []interface{}{1, "https://via.placeholder.com/300/06f/fff.png", 1, 2, "https://via.placeholder.com/300/07f/fff.png", 1, 3, "https://via.placeholder.com/300/08f/fff.png", 1}
|
||||||
|
var app *fiber.App = v1.New()
|
||||||
|
|
||||||
func cleanup() {
|
func cleanup() {
|
||||||
_, err := db.Query(context.Background(), "DROP TABLE \"jokesbapak2\"")
|
j, err := db.Query(context.Background(), "DROP TABLE \"jokesbapak2\"")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
_, err = db.Query(context.Background(), "DROP TABLE \"administrators\"")
|
a, err := db.Query(context.Background(), "DROP TABLE \"administrators\"")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer j.Close()
|
||||||
|
defer a.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup() error {
|
||||||
|
err := database.Setup()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hashedToken := "$argon2id$v=19$m=65536,t=16,p=4$48beb241490caa57fbca8e63df1e1b5fba8934baf78205ee775f96a85f45b889$e6dfca3f69adbe7653dbb353f366d741a3640313c45e33eabaca0c217c16417de80d70ac67f217c9ca46634b0abaad5f4ea2b064caa44ce218fb110b4cba9d36"
|
||||||
|
var args []interface{} = []interface{}{1, "very secure", hashedToken, time.Now().Format(time.RFC3339)}
|
||||||
|
a, err := db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", args...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer a.Close()
|
||||||
|
|
||||||
|
j, err := db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer j.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Need to find some workaround for this test
|
/// Need to find some workaround for this test
|
||||||
func TestJokeGet(t *testing.T) {
|
func TestTodayJoke(t *testing.T) {
|
||||||
err := database.Setup()
|
err := setup()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", "not the real one", time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
defer cleanup()
|
||||||
|
|
||||||
app := v1.New()
|
req, _ := http.NewRequest("GET", "/today", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
t.Run("TodayJoke - should return 200", func(t *testing.T) {
|
assert.Equalf(t, false, err != nil, "today joke")
|
||||||
req, _ := http.NewRequest("GET", "/today", nil)
|
assert.Equalf(t, 200, res.StatusCode, "today joke")
|
||||||
res, err := app.Test(req, -1)
|
assert.NotEqualf(t, 0, res.ContentLength, "today joke")
|
||||||
|
_, err = ioutil.ReadAll(res.Body)
|
||||||
assert.Equalf(t, false, err != nil, "today joke")
|
assert.Nilf(t, err, "today joke")
|
||||||
assert.Equalf(t, 200, res.StatusCode, "today joke")
|
}
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "today joke")
|
|
||||||
_, err = ioutil.ReadAll(res.Body)
|
func TestSingleJoke(t *testing.T) {
|
||||||
assert.Nilf(t, err, "today joke")
|
err := setup()
|
||||||
})
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
t.Run("SingleJoke - should return 200", func(t *testing.T) {
|
}
|
||||||
req, _ := http.NewRequest("GET", "/", nil)
|
|
||||||
res, err := app.Test(req, -1)
|
defer cleanup()
|
||||||
|
|
||||||
assert.Equalf(t, false, err != nil, "single joke")
|
req, _ := http.NewRequest("GET", "/", nil)
|
||||||
assert.Equalf(t, 200, res.StatusCode, "single joke")
|
res, err := app.Test(req, -1)
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "single joke")
|
|
||||||
_, err = ioutil.ReadAll(res.Body)
|
assert.Equalf(t, false, err != nil, "single joke")
|
||||||
assert.Nilf(t, err, "single joke")
|
assert.Equalf(t, 200, res.StatusCode, "single joke")
|
||||||
})
|
assert.NotEqualf(t, 0, res.ContentLength, "single joke")
|
||||||
|
_, err = ioutil.ReadAll(res.Body)
|
||||||
t.Run("JokeByID - should return 200", func(t *testing.T) {
|
assert.Nilf(t, err, "single joke")
|
||||||
req, _ := http.NewRequest("GET", "/id/1", nil)
|
}
|
||||||
res, err := app.Test(req, -1)
|
|
||||||
|
func TestJokeByID_200(t *testing.T) {
|
||||||
assert.Equalf(t, false, err != nil, "joke by id")
|
err := setup()
|
||||||
assert.Equalf(t, 200, res.StatusCode, "joke by id")
|
if err != nil {
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke by id")
|
t.Fatal(err)
|
||||||
_, err = ioutil.ReadAll(res.Body)
|
}
|
||||||
assert.Nilf(t, err, "joke by id")
|
|
||||||
})
|
defer cleanup()
|
||||||
|
|
||||||
t.Run("JokeByID - should return 404", func(t *testing.T) {
|
req, _ := http.NewRequest("GET", "/id/1", nil)
|
||||||
req, _ := http.NewRequest("GET", "/id/300", nil)
|
res, err := app.Test(req, -1)
|
||||||
res, err := app.Test(req, -1)
|
|
||||||
|
assert.Equalf(t, false, err != nil, "joke by id")
|
||||||
assert.Equalf(t, false, err != nil, "joke by id")
|
assert.Equalf(t, 200, res.StatusCode, "joke by id")
|
||||||
assert.Equalf(t, 404, res.StatusCode, "joke by id")
|
assert.NotEqualf(t, 0, res.ContentLength, "joke by id")
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke by id")
|
_, err = ioutil.ReadAll(res.Body)
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
assert.Nilf(t, err, "joke by id")
|
||||||
assert.Nilf(t, err, "joke by id")
|
}
|
||||||
assert.Equalf(t, "Requested ID was not found.", string(body), "joke by id")
|
|
||||||
})
|
func TestJokeByID_404(t *testing.T) {
|
||||||
|
err := setup()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("GET", "/id/300", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
|
assert.Equalf(t, false, err != nil, "joke by id")
|
||||||
|
assert.Equalf(t, 404, res.StatusCode, "joke by id")
|
||||||
|
assert.NotEqualf(t, 0, res.ContentLength, "joke by id")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "joke by id")
|
||||||
|
assert.Equalf(t, "Requested ID was not found.", string(body), "joke by id")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,30 @@
|
||||||
package joke_test
|
package joke_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
v1 "jokes-bapak2-api/app/v1"
|
|
||||||
"jokes-bapak2-api/app/v1/handler"
|
|
||||||
"jokes-bapak2-api/app/v1/platform/database"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTotalJokes(t *testing.T) {
|
func TestTotalJokes(t *testing.T) {
|
||||||
err := database.Setup()
|
err := setup()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", "not the real one", time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
defer cleanup()
|
||||||
|
|
||||||
app := v1.New()
|
req, _ := http.NewRequest("GET", "/total", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
t.Run("Total - should return 200", func(t *testing.T) {
|
assert.Equalf(t, false, err != nil, "joke total")
|
||||||
req, _ := http.NewRequest("GET", "/total", nil)
|
assert.Equalf(t, 200, res.StatusCode, "joke total")
|
||||||
res, err := app.Test(req, -1)
|
assert.NotEqualf(t, 0, res.ContentLength, "joke total")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "joke total")
|
||||||
|
// FIXME: This should be "message": "3", not one. I don't know what's wrong as it's 1 AM.
|
||||||
|
assert.Equalf(t, "{\"message\":\"3\"}", string(body), "joke total")
|
||||||
|
|
||||||
assert.Equalf(t, false, err != nil, "joke total")
|
|
||||||
assert.Equalf(t, 200, res.StatusCode, "joke total")
|
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke total")
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
|
||||||
assert.Nilf(t, err, "joke total")
|
|
||||||
// FIXME: This should be "message": "3", not one. I don't know what's wrong as it's 1 AM.
|
|
||||||
assert.Equalf(t, "{\"message\":\"1\"}", string(body), "joke total")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,13 @@ func UpdateJoke(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = handler.Db.Query(context.Background(), sql, args...)
|
r, err := handler.Db.Query(context.Background(), sql, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
err = core.SetAllJSONJoke(handler.Db, handler.Memory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,62 +1,50 @@
|
||||||
package joke_test
|
package joke_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
v1 "jokes-bapak2-api/app/v1"
|
|
||||||
"jokes-bapak2-api/app/v1/handler"
|
|
||||||
"jokes-bapak2-api/app/v1/platform/database"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpdateJoke(t *testing.T) {
|
func TestUpdateJoke_200(t *testing.T) {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
err := database.Setup()
|
err := setup()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
hashedToken := "$argon2id$v=19$m=65536,t=16,p=4$48beb241490caa57fbca8e63df1e1b5fba8934baf78205ee775f96a85f45b889$e6dfca3f69adbe7653dbb353f366d741a3640313c45e33eabaca0c217c16417de80d70ac67f217c9ca46634b0abaad5f4ea2b064caa44ce218fb110b4cba9d36"
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"administrators\" (id, key, token, last_used) VALUES ($1, $2, $3, $4);", 1, "very secure", hashedToken, time.Now().Format(time.RFC3339))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = handler.Db.Query(context.Background(), "INSERT INTO \"jokesbapak2\" (id, link, creator) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);", jokesData...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
t.Cleanup(cleanup)
|
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
|
req, _ := http.NewRequest("PATCH", "/id/1", reqBody)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
app := v1.New()
|
assert.Equalf(t, false, err != nil, "joke update")
|
||||||
|
assert.Equalf(t, 200, res.StatusCode, "joke update")
|
||||||
t.Run("Update - should return 200", func(t *testing.T) {
|
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
|
||||||
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"very secure\",\"token\":\"password\"}")
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
req, _ := http.NewRequest("PATCH", "/id/1", reqBody)
|
assert.Nilf(t, err, "joke update")
|
||||||
res, err := app.Test(req, -1)
|
assert.Equalf(t, "{\"message\":\"specified joke id has been deleted\"}", string(body), "joke update")
|
||||||
|
}
|
||||||
assert.Equalf(t, false, err != nil, "joke update")
|
|
||||||
assert.Equalf(t, 200, res.StatusCode, "joke update")
|
func TestUpdateJoke_NotExists(t *testing.T) {
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
|
t.SkipNow()
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
err := setup()
|
||||||
assert.Nilf(t, err, "joke update")
|
if err != nil {
|
||||||
assert.Equalf(t, "{\"message\":\"specified joke id has been deleted\"}", string(body), "joke update")
|
t.Fatal(err)
|
||||||
})
|
}
|
||||||
|
defer cleanup()
|
||||||
t.Run("Update - id doesn't exists", func(t *testing.T) {
|
|
||||||
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"very secure\",\"token\":\"password\"}")
|
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||||
req, _ := http.NewRequest("PATCH", "/id/100", reqBody)
|
req, _ := http.NewRequest("PATCH", "/id/100", reqBody)
|
||||||
res, err := app.Test(req, -1)
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
assert.Equalf(t, false, err != nil, "joke update")
|
assert.Equalf(t, false, err != nil, "joke update")
|
||||||
assert.Equalf(t, 406, res.StatusCode, "joke update")
|
assert.Equalf(t, 406, res.StatusCode, "joke update")
|
||||||
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
|
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
assert.Nilf(t, err, "joke update")
|
assert.Nilf(t, err, "joke update")
|
||||||
assert.Equalf(t, "{\"message\":\"specified joke id does not exists\"}", string(body), "joke update")
|
assert.Equalf(t, "{\"message\":\"specified joke id does not exists\"}", string(body), "joke update")
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
package submit_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io/ioutil"
|
||||||
|
v1 "jokes-bapak2-api/app/v1"
|
||||||
|
"jokes-bapak2-api/app/v1/platform/database"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/jackc/pgx/v4/pgxpool"
|
||||||
|
_ "github.com/joho/godotenv/autoload"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
var db *pgxpool.Pool = database.New()
|
||||||
|
var submissionData = []interface{}{1, "https://via.placeholder.com/300/01f/fff.png", "2021-08-03T18:20:38Z", "Test <test@example.com>", 0, 2, "https://via.placeholder.com/300/02f/fff.png", "2021-08-04T18:20:38Z", "Test <test@example.com>", 1}
|
||||||
|
var app *fiber.App = v1.New()
|
||||||
|
|
||||||
|
func cleanup() {
|
||||||
|
s, err := db.Query(context.Background(), "DROP TABLE \"submission\"")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer s.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup() error {
|
||||||
|
err := database.Setup()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := db.Query(context.Background(), "INSERT INTO \"submission\" (id, link, created_at, author, status) VALUES ($1, $2, $3, $4, $5), ($6, $7, $8, $9, $10);", submissionData...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func TestGetSubmission_200(t *testing.T) {
|
||||||
|
err := setup()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("GET", "/submit", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
|
assert.Equalf(t, false, err != nil, "get submission")
|
||||||
|
assert.Equalf(t, 200, res.StatusCode, "get submission")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "get submission")
|
||||||
|
assert.Equalf(t, "{\"count\":2,\"jokes\":[{\"id\":1,\"link\":\"https://via.placeholder.com/300/01f/fff.png\",\"created_at\":\"2021-08-03T18:20:38Z\",\"author\":\"Test \\u003ctest@example.com\\u003e\",\"status\":0},{\"id\":2,\"link\":\"https://via.placeholder.com/300/02f/fff.png\",\"created_at\":\"2021-08-04T18:20:38Z\",\"author\":\"Test \\u003ctest@example.com\\u003e\",\"status\":1}]}", string(body), "get submission")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetSubmission_Params(t *testing.T) {
|
||||||
|
err := setup()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("GET", "/submit?page=1&limit=5&approved=true", nil)
|
||||||
|
res, err := app.Test(req, -1)
|
||||||
|
|
||||||
|
assert.Equalf(t, false, err != nil, "get submission")
|
||||||
|
assert.Equalf(t, 200, res.StatusCode, "get submission")
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
assert.Nilf(t, err, "get submission")
|
||||||
|
assert.Equalf(t, "{\"count\":1,\"jokes\":[{\"id\":2,\"link\":\"https://via.placeholder.com/300/02f/fff.png\",\"created_at\":\"2021-08-04T18:20:38Z\",\"author\":\"Test \\u003ctest@example.com\\u003e\",\"status\":1}]}", string(body), "get submission")
|
||||||
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
package models
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var ErrNoRows = errors.New("no rows in result set")
|
|
||||||
var ErrConnDone = errors.New("connection is already closed")
|
|
||||||
var ErrTxDone = errors.New("transaction has already been committed or rolled back")
|
|
||||||
|
|
||||||
var ErrNotFound = errors.New("record not found")
|
|
||||||
var ErrEmpty = errors.New("record is empty")
|
|
|
@ -76,5 +76,38 @@ func Setup() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Submission table
|
||||||
|
|
||||||
|
//Check if table exists
|
||||||
|
var tableSubmissionExists bool
|
||||||
|
err = db.QueryRow(context.Background(), `SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'submission'
|
||||||
|
);`).Scan(&tableJokesExists)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("13 - failed on checking table: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !tableSubmissionExists {
|
||||||
|
sql, _, err := bob.
|
||||||
|
CreateTable("submission").
|
||||||
|
AddColumn(bob.ColumnDef{Name: "id", Type: "SERIAL", Extras: []string{"PRIMARY KEY"}}).
|
||||||
|
TextColumn("link", "UNIQUE", "NOT NULL").
|
||||||
|
StringColumn("created_at").
|
||||||
|
StringColumn("author", "NOT NULL").
|
||||||
|
AddColumn(bob.ColumnDef{Name: "status", Type: "SMALLINT", Extras: []string{"DEFAULT 0"}}).
|
||||||
|
ToSql()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("14 - failed on table creation: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Query(context.Background(), sql)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("15 - failed on table creation: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,18 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsIn(t *testing.T) {
|
func TestIsIn_True(t *testing.T) {
|
||||||
arr := []string{"John", "Matthew", "Thomas", "Adam"}
|
arr := []string{"John", "Matthew", "Thomas", "Adam"}
|
||||||
t.Run("should return true", func(t *testing.T) {
|
check := utils.IsIn(arr, "Thomas")
|
||||||
check := utils.IsIn(arr, "Thomas")
|
if !check {
|
||||||
if !check {
|
t.Error("check should be true: ", check)
|
||||||
t.Error("check should be true: ", check)
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
func TestIsIn_False(t *testing.T) {
|
||||||
t.Run("should return false", func(t *testing.T) {
|
arr := []string{"John", "Matthew", "Thomas", "Adam"}
|
||||||
check := utils.IsIn(arr, "James")
|
check := utils.IsIn(arr, "James")
|
||||||
if check {
|
if check {
|
||||||
t.Error("check should be false: ", check)
|
t.Error("check should be false: ", check)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,34 +7,42 @@ import (
|
||||||
"jokes-bapak2-api/app/v1/utils"
|
"jokes-bapak2-api/app/v1/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsToday(t *testing.T) {
|
func TestIsToday_Today(t *testing.T) {
|
||||||
t.Run("should be able to tell if it's today", func(t *testing.T) {
|
today, err := utils.IsToday(time.Now().Format(time.RFC3339))
|
||||||
today, err := utils.IsToday(time.Now().Format(time.RFC3339))
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err.Error())
|
||||||
t.Error(err.Error())
|
}
|
||||||
}
|
if today == false {
|
||||||
if today == false {
|
t.Error("today should be true:", today)
|
||||||
t.Error("today should be true:", today)
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
func TestIsToday_NotToday(t *testing.T) {
|
||||||
t.Run("should be able to tell if it's not today", func(t *testing.T) {
|
today, err := utils.IsToday("2021-01-01T11:48:24Z")
|
||||||
today, err := utils.IsToday("2021-01-01T11:48:24Z")
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err.Error())
|
||||||
t.Error(err.Error())
|
}
|
||||||
}
|
if today == true {
|
||||||
if today == true {
|
t.Error("today should be false:", today)
|
||||||
t.Error("today should be false:", today)
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
func TestIsToday_ErrorIfEmpty(t *testing.T) {
|
||||||
t.Run("should return false with no error if no date is supplied", func(t *testing.T) {
|
today, err := utils.IsToday("")
|
||||||
today, err := utils.IsToday("")
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err.Error())
|
||||||
t.Error(err.Error())
|
}
|
||||||
}
|
if today != false {
|
||||||
if today != false {
|
t.Error("it should be false:", today)
|
||||||
t.Error("it should be false:", today)
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
func TestIsToday_ErrorIfInvalid(t *testing.T) {
|
||||||
|
today, err := utils.IsToday("asdfghjkl")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("it should be error:", today, err)
|
||||||
|
}
|
||||||
|
if today != false {
|
||||||
|
t.Error("it should be false:", today)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,37 +8,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseToJSONBody(t *testing.T) {
|
func TestParseToJSONBody(t *testing.T) {
|
||||||
t.Run("should be able to parse a json string", func(t *testing.T) {
|
body := map[string]interface{}{
|
||||||
body := map[string]interface{}{
|
"name": "Scott",
|
||||||
"name": "Scott",
|
"age": 32,
|
||||||
"age": 32,
|
"fat": true,
|
||||||
"fat": true,
|
}
|
||||||
}
|
parsed, err := utils.ParseToJSONBody(body)
|
||||||
parsed, err := utils.ParseToJSONBody(body)
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err.Error())
|
||||||
t.Error(err.Error())
|
}
|
||||||
}
|
result := "{\"age\":32,\"fat\":true,\"name\":\"Scott\"}"
|
||||||
result := "{\"age\":32,\"fat\":true,\"name\":\"Scott\"}"
|
if string(parsed) != result {
|
||||||
if string(parsed) != result {
|
t.Error("parsed string is not the same as result:", string(parsed))
|
||||||
t.Error("parsed string is not the same as result:", string(parsed))
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseToFormBody(t *testing.T) {
|
func TestParseToFormBody(t *testing.T) {
|
||||||
t.Run("should be able to parse a form body", func(t *testing.T) {
|
body := map[string]interface{}{
|
||||||
body := map[string]interface{}{
|
"age": 32,
|
||||||
"age": 32,
|
"fat": true,
|
||||||
"fat": true,
|
"name": "Scott",
|
||||||
"name": "Scott",
|
}
|
||||||
}
|
parsed, err := utils.ParseToFormBody(body)
|
||||||
parsed, err := utils.ParseToFormBody(body)
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err.Error())
|
||||||
t.Error(err.Error())
|
}
|
||||||
}
|
result := [3]string{"age=32&", "fat=true&", "name=Scott&"}
|
||||||
result := [3]string{"age=32&", "fat=true&", "name=Scott&"}
|
if !strings.Contains(string(parsed), result[0]) && !strings.Contains(string(parsed), result[1]) && !strings.Contains(string(parsed), result[2]) {
|
||||||
if !strings.Contains(string(parsed), result[0]) && !strings.Contains(string(parsed), result[1]) && !strings.Contains(string(parsed), result[2]) {
|
t.Error("parsed string is not the same as result:", string(parsed))
|
||||||
t.Error("parsed string is not the same as result:", string(parsed))
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,22 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRandomString(t *testing.T) {
|
func TestRandomString_Valid(t *testing.T) {
|
||||||
t.Run("should create a random string with param", func(t *testing.T) {
|
random, err := utils.RandomString(10)
|
||||||
random, err := utils.RandomString(10)
|
if err != nil {
|
||||||
if err != nil {
|
t.Error(err)
|
||||||
t.Error(err)
|
}
|
||||||
}
|
if len(random) != 20 {
|
||||||
if len(random) != 20 {
|
t.Error("result is not within the length of 10")
|
||||||
t.Error("result is not within the length of 10")
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
t.Run("should create a random string with invalid params", func(t *testing.T) {
|
func TestRandomString_Invalid(t *testing.T) {
|
||||||
random, err := utils.RandomString(10)
|
random, err := utils.RandomString(10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if len(random) != 20 {
|
if len(random) != 20 {
|
||||||
t.Error("result is not within the length of 10")
|
t.Error("result is not within the length of 10")
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
|
@ -7,21 +7,19 @@ import (
|
||||||
"jokes-bapak2-api/app/v1/utils"
|
"jokes-bapak2-api/app/v1/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRequest(t *testing.T) {
|
func TestRequest_Get(t *testing.T) {
|
||||||
t.Run("should be able to do a get request", func(t *testing.T) {
|
res, err := utils.Request(utils.RequestConfig{
|
||||||
res, err := utils.Request(utils.RequestConfig{
|
URL: "https://jsonplaceholder.typicode.com/todos/1",
|
||||||
URL: "https://jsonplaceholder.typicode.com/todos/1",
|
Method: http.MethodGet,
|
||||||
Method: http.MethodGet,
|
Headers: map[string]interface{}{
|
||||||
Headers: map[string]interface{}{
|
"User-Agent": "Jokesbapak2 Test API",
|
||||||
"User-Agent": "Jokesbapak2 Test API",
|
"Accept": "application/json",
|
||||||
"Accept": "application/json",
|
},
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err.Error())
|
|
||||||
}
|
|
||||||
if res.StatusCode != 200 {
|
|
||||||
t.Error("response does not have 200 status", res.Status)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
t.Error("response does not have 200 status", res.Status)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,12 @@ require (
|
||||||
github.com/gojek/heimdall/v7 v7.0.2
|
github.com/gojek/heimdall/v7 v7.0.2
|
||||||
github.com/jackc/pgx/v4 v4.12.0
|
github.com/jackc/pgx/v4 v4.12.0
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
|
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
)
|
)
|
||||||
|
|
19
api/go.sum
19
api/go.sum
|
@ -70,6 +70,7 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
|
||||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -308,12 +309,12 @@ github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
|
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
|
||||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
|
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
|
||||||
|
@ -372,6 +373,8 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE
|
||||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||||
|
@ -623,8 +626,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
@ -688,8 +692,9 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
@ -708,11 +713,13 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
|
@ -67,7 +67,7 @@ func StartServerWithGracefulShutdown(a *fiber.App) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Run server.
|
// Run server.
|
||||||
if err := a.Listen(":" + os.Getenv("PORT")); err != nil {
|
if err := a.Listen(os.Getenv("HOST") + ":" + os.Getenv("PORT")); err != nil {
|
||||||
log.Printf("Oops... Server is not running! Reason: %v", err)
|
log.Printf("Oops... Server is not running! Reason: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func StartServerWithGracefulShutdown(a *fiber.App) {
|
||||||
// StartServer func for starting a simple server.
|
// StartServer func for starting a simple server.
|
||||||
func StartServer(a *fiber.App) {
|
func StartServer(a *fiber.App) {
|
||||||
// Run server.
|
// Run server.
|
||||||
if err := a.Listen(":" + os.Getenv("PORT")); err != nil {
|
if err := a.Listen(os.Getenv("HOST") + ":" + os.Getenv("PORT")); err != nil {
|
||||||
log.Printf("Oops... Server is not running! Reason: %v", err)
|
log.Printf("Oops... Server is not running! Reason: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue