Cleanup
This commit is contained in:
57
main_test.go
57
main_test.go
@ -1,11 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/api"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func TestRoutes(t *testing.T) {
|
||||
@ -23,9 +28,55 @@ func TestRoutes(t *testing.T) {
|
||||
app.Handler().ServeHTTP(responseRecorder, request)
|
||||
|
||||
if status := responseRecorder.Code; status != http.StatusOK {
|
||||
t.Errorf("%s | Wrong status code | %v instead of %v", example, status, http.StatusOK)
|
||||
} else {
|
||||
t.Logf("%s | Correct status code | %v == %v", example, status, http.StatusOK)
|
||||
color.Red("%s | Wrong status code | %v instead of %v", example, status, http.StatusOK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterfaceImplementations(t *testing.T) {
|
||||
// API interfaces
|
||||
var creatable = reflect.TypeOf((*api.Creatable)(nil)).Elem()
|
||||
var updatable = reflect.TypeOf((*api.Updatable)(nil)).Elem()
|
||||
var actionable = reflect.TypeOf((*api.Actionable)(nil)).Elem()
|
||||
var collection = reflect.TypeOf((*api.Collection)(nil)).Elem()
|
||||
|
||||
// Required interface implementations
|
||||
var interfaceImplementations = map[string][]reflect.Type{
|
||||
"User": []reflect.Type{
|
||||
updatable,
|
||||
},
|
||||
"Thread": []reflect.Type{
|
||||
creatable,
|
||||
updatable,
|
||||
actionable,
|
||||
},
|
||||
"Post": []reflect.Type{
|
||||
creatable,
|
||||
updatable,
|
||||
actionable,
|
||||
},
|
||||
"SoundTrack": []reflect.Type{
|
||||
creatable,
|
||||
},
|
||||
"Analytics": []reflect.Type{
|
||||
creatable,
|
||||
},
|
||||
"AnimeList": []reflect.Type{
|
||||
collection,
|
||||
},
|
||||
"PushSubscriptions": []reflect.Type{
|
||||
collection,
|
||||
},
|
||||
"UserFollows": []reflect.Type{
|
||||
collection,
|
||||
},
|
||||
}
|
||||
|
||||
for typeName, interfaces := range interfaceImplementations {
|
||||
for _, requiredInterface := range interfaces {
|
||||
if !reflect.PtrTo(arn.DB.Type(typeName)).Implements(requiredInterface) {
|
||||
panic(errors.New(typeName + " does not implement interface " + requiredInterface.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user