2016-10-13 16:25:01 +02:00
|
|
|
// Black-box Testing
|
|
|
|
package iris_test
|
2016-09-09 07:09:03 +02:00
|
|
|
|
|
|
|
import (
|
2016-10-13 16:25:01 +02:00
|
|
|
"github.com/kataras/iris"
|
2016-09-09 07:09:03 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// go test -v -run TestConfig*
|
|
|
|
|
|
|
|
func TestConfigStatic(t *testing.T) {
|
2016-10-13 16:25:01 +02:00
|
|
|
def := iris.DefaultConfiguration()
|
2016-09-09 07:09:03 +02:00
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
api := iris.New(def)
|
2016-09-09 07:09:03 +02:00
|
|
|
afterNew := *api.Config
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(def, afterNew) {
|
|
|
|
t.Fatalf("Default configuration is not the same after NewFromConfig expected:\n %#v \ngot:\n %#v", def, afterNew)
|
|
|
|
}
|
|
|
|
|
|
|
|
afterNew.Charset = "changed"
|
|
|
|
|
|
|
|
if reflect.DeepEqual(def, afterNew) {
|
|
|
|
t.Fatalf("Configuration should be not equal, got: %#v", afterNew)
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
api = iris.New(iris.Configuration{IsDevelopment: true})
|
2016-09-09 07:09:03 +02:00
|
|
|
|
|
|
|
afterNew = *api.Config
|
|
|
|
|
|
|
|
if api.Config.IsDevelopment == false {
|
|
|
|
t.Fatalf("Passing a Configuration field as Option fails, expected IsDevelopment to be true but was false")
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
api = iris.New() // empty , means defaults so
|
2016-09-09 07:09:03 +02:00
|
|
|
if !reflect.DeepEqual(def, *api.Config) {
|
|
|
|
t.Fatalf("Default configuration is not the same after NewFromConfig expected:\n %#v \ngot:\n %#v", def, *api.Config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigOptions(t *testing.T) {
|
|
|
|
charset := "MYCHARSET"
|
|
|
|
dev := true
|
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
api := iris.New(iris.OptionCharset(charset), iris.OptionIsDevelopment(dev))
|
2016-09-09 07:09:03 +02:00
|
|
|
|
|
|
|
if got := api.Config.Charset; got != charset {
|
|
|
|
t.Fatalf("Expected configuration Charset to be: %s but got: %s", charset, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
if got := api.Config.IsDevelopment; got != dev {
|
|
|
|
t.Fatalf("Expected configuration IsDevelopment to be: %#v but got: %#v", dev, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check if other default values are setted (should be setted automatically)
|
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
expected := iris.DefaultConfiguration()
|
2016-09-09 07:09:03 +02:00
|
|
|
expected.Charset = charset
|
|
|
|
expected.IsDevelopment = dev
|
|
|
|
|
|
|
|
has := *api.Config
|
|
|
|
if !reflect.DeepEqual(has, expected) {
|
|
|
|
t.Fatalf("Default configuration is not the same after New expected:\n %#v \ngot:\n %#v", expected, has)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigOptionsDeep(t *testing.T) {
|
|
|
|
cookiename := "MYSESSIONID"
|
|
|
|
charset := "MYCHARSET"
|
|
|
|
dev := true
|
2016-09-27 15:28:38 +02:00
|
|
|
vhost := "mydomain.com"
|
2016-09-09 07:09:03 +02:00
|
|
|
// first session, after charset,dev and profilepath, no canonical order.
|
2016-10-13 16:25:01 +02:00
|
|
|
api := iris.New(iris.OptionSessionsCookie(cookiename), iris.OptionCharset(charset), iris.OptionIsDevelopment(dev), iris.OptionVHost(vhost))
|
2016-09-09 07:09:03 +02:00
|
|
|
|
2016-10-13 16:25:01 +02:00
|
|
|
expected := iris.DefaultConfiguration()
|
2016-09-09 07:09:03 +02:00
|
|
|
expected.Sessions.Cookie = cookiename
|
|
|
|
expected.Charset = charset
|
|
|
|
expected.IsDevelopment = dev
|
2016-09-27 15:28:38 +02:00
|
|
|
expected.VHost = vhost
|
2016-09-09 07:09:03 +02:00
|
|
|
|
|
|
|
has := *api.Config
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(has, expected) {
|
|
|
|
t.Fatalf("DEEP configuration is not the same after New expected:\n %#v \ngot:\n %#v", expected, has)
|
|
|
|
}
|
|
|
|
}
|