genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
hs_monolith/http/good_test.go

72 lines
2.0 KiB
Go
Raw Normal View History

// Package that contains all api routes of this microservice
2017-04-29 18:26:36 +02:00
package http
import (
"net/http"
"testing"
"time"
"github.com/genofire/hs_master-kss-monolith/lib/database"
"github.com/genofire/hs_master-kss-monolith/models"
"github.com/genofire/hs_master-kss-monolith/runtime"
"github.com/genofire/hs_master-kss-monolith/test"
)
// Function to test addGood()
2017-04-29 18:26:36 +02:00
func TestAddGood(t *testing.T) {
assertion, router := test.Init(t)
BindAPI(router)
runtime.PermissionURL = "http://localhost:8080/api-test/session/%s/%d/"
session := test.NewSession(router)
good := models.Good{
ProductID: 3,
Comment: "blub",
}
_, w := session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusNonAuthoritativeInfo, w.StatusCode)
session.Login()
_, w = session.JSONRequest("POST", "/api/good/a", good)
assertion.Equal(http.StatusNotAcceptable, w.StatusCode)
2017-05-07 15:38:08 +02:00
_, w = session.JSONRequest("POST", "/api/good/7", good)
2017-04-29 18:26:36 +02:00
assertion.Equal(http.StatusNotFound, w.StatusCode)
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusOK, w.StatusCode)
database.Close()
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusInternalServerError, w.StatusCode)
session.Logout()
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusForbidden, w.StatusCode)
session.Login()
runtime.CacheConfig.After = models.Duration{Duration: time.Duration(5) * time.Millisecond}
test.CloseServer()
time.Sleep(time.Duration(10) * time.Millisecond)
runtime.HasPermission("testsessionkey", runtime.PermissionCreateGood)
runtime.CleanCache()
// Test gatewaytimeout on product exists
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusGatewayTimeout, w.StatusCode)
time.Sleep(time.Duration(10) * time.Millisecond)
runtime.CleanCache()
// Test gatewaytimeout on permission exists
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusGatewayTimeout, w.StatusCode)
test.Close()
}