add: server shutdown, tests
This commit is contained in:
@@ -44,7 +44,7 @@ var (
|
||||
|
||||
func TestSuite(t *testing.T) {
|
||||
_ = deleteTestDB("test.db")
|
||||
if err := database.InitDB("test.db"); err != nil {
|
||||
if err := database.Open("test.db"); err != nil {
|
||||
log.Fatalf("Failed to create DB: %#v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,15 @@ func (mc *MembershipController) RegisterSubscription(c *gin.Context) {
|
||||
}
|
||||
|
||||
logger.Info.Printf("Using API key: %v", config.Auth.APIKEY)
|
||||
|
||||
if regData.APIKey == "" {
|
||||
logger.Error.Println("API Key is missing")
|
||||
c.JSON(http.StatusBadRequest, "API Key is missing")
|
||||
c.JSON(http.StatusUnauthorized, "API Key is missing")
|
||||
return
|
||||
}
|
||||
|
||||
if regData.APIKey != config.Auth.APIKEY {
|
||||
logger.Error.Printf("API Key not valid: %v", regData.APIKey)
|
||||
c.JSON(http.StatusExpectationFailed, "API Key is missing")
|
||||
c.JSON(http.StatusUnauthorized, "API Key is missing")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,28 @@ func customizeSubscription(customize func(MembershipData) MembershipData) Member
|
||||
|
||||
func getSubscriptionData() []RegisterSubscriptionTest {
|
||||
return []RegisterSubscriptionTest{
|
||||
{
|
||||
Name: "No API Key should fail",
|
||||
WantResponse: http.StatusUnauthorized,
|
||||
WantDBData: map[string]interface{}{"name": "Just a Subscription"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription MembershipData) MembershipData {
|
||||
subscription.APIKey = ""
|
||||
return subscription
|
||||
})),
|
||||
},
|
||||
{
|
||||
Name: "Wrong API Key should fail",
|
||||
WantResponse: http.StatusUnauthorized,
|
||||
WantDBData: map[string]interface{}{"name": "Just a Subscription"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription MembershipData) MembershipData {
|
||||
subscription.APIKey = "alskfdlkjsfjk23-dF"
|
||||
return subscription
|
||||
})),
|
||||
},
|
||||
{
|
||||
Name: "No Details should fail",
|
||||
WantResponse: http.StatusNotAcceptable,
|
||||
|
||||
Reference in New Issue
Block a user