Cover replica scaling with tests.

This commit is contained in:
Alex
2017-01-30 21:16:54 +00:00
parent 52266a6741
commit c211ba0d07
3 changed files with 74 additions and 49 deletions

View File

@ -0,0 +1,47 @@
package tests
import (
"testing"
"github.com/alexellis/faas/gateway/handlers"
)
func TestScale1to5(t *testing.T) {
newReplicas := handlers.CalculateReplicas("firing", 1)
if newReplicas != 5 {
t.Log("Expected increment in blocks of 5 from 1 to 5")
t.Fail()
}
}
func TestScale5to10(t *testing.T) {
newReplicas := handlers.CalculateReplicas("firing", 5)
if newReplicas != 10 {
t.Log("Expected increment in blocks of 5 from 5 to 10")
t.Fail()
}
}
func TestScaleCeilingOf20Replicas_Noaction(t *testing.T) {
newReplicas := handlers.CalculateReplicas("firing", 20)
if newReplicas != 20 {
t.Log("Expected ceiling of 20 replicas")
t.Fail()
}
}
func TestScaleCeilingOf20Replicas(t *testing.T) {
newReplicas := handlers.CalculateReplicas("firing", 19)
if newReplicas != 20 {
t.Log("Expected ceiling of 20 replicas")
t.Fail()
}
}
func TestBackingOff10to1(t *testing.T) {
newReplicas := handlers.CalculateReplicas("resolved", 10)
if newReplicas != 1 {
t.Log("Expected backing off to 1 replica")
t.Fail()
}
}

View File

@ -1,27 +0,0 @@
package tests
import (
"testing"
"io/ioutil"
"github.com/alexellis/faas/gateway/handlers"
"github.com/alexellis/faas/gateway/requests"
)
func TestIsAlexa(t *testing.T) {
requestBody, _ := ioutil.ReadFile("./alexhostname_request.json")
var result requests.AlexaRequestBody
result = handlers.IsAlexa(requestBody)
if len(result.Session.Application.ApplicationId) == 0 {
t.Fail()
}
if len(result.Session.SessionId) == 0 {
t.Fail()
}
if len(result.Request.Intent.Name) == 0 {
t.Fail()
}
}