Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Go 1.7 Sub tests
package controller_test
import (
"testing"
"github.com/almighty/almighty-core/app/test"
"github.com/almighty/almighty-core/application"
. "github.com/almighty/almighty-core/controller"
"github.com/almighty/almighty-core/gormsupport/cleaner"
testsupport "github.com/almighty/almighty-core/test"
almtoken "github.com/almighty/almighty-core/token"
"github.com/goadesign/goa"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/almighty/almighty-core/gormapplication"
)
func TestIterations(t *testing.T) {
db := resource.Require(t, resource.Database)
app := gormapplication.NewGormDB(db)
defer cleaner.DeleteCreatedEntities(db)()
svc, ctrl := iterationController(app)
t.Run("ShowSuccess", showSuccess(app, svc, ctrl))
t.Run("UpdateSuccess", showSuccess(app, svc, ctrl))
t.Run("ListSuccess", showSuccess(app, svc, ctrl))
t.Run("DeleteSuccess", showSuccess(app, svc, ctrl))
}
func showSuccess(db *application.DB, svc *goa.Service, ctrl *IterationController) func(t *testing.T) {
return func(t *testing.T) {
itrID := createSpaceAndIteration(t, db)
_, created := test.ShowIterationOK(t, svc.Context, svc, ctrl, itrID.ID.String())
assertIterationLinking(t, created.Data)
require.NotNil(t, created.Data.Relationships.Workitems.Meta)
assert.Equal(t, 0, created.Data.Relationships.Workitems.Meta["total"])
assert.Equal(t, 0, created.Data.Relationships.Workitems.Meta["closed"])
}
}
// local helper functions
func iterationController(db *application.DB) (*goa.Service, *IterationController) {
priv, _ := almtoken.ParsePrivateKey([]byte(almtoken.RSAPrivateKey))
svc := testsupport.ServiceAsUser("Iteration-Service", almtoken.NewManagerWithPrivateKey(priv), testsupport.TestIdentity)
return svc, NewIterationController(svc, *db)
}
// helper functions from db package etc
func database() *gorm.DB {
return nil
}
func appdatabase(db *gorm.DB) *application.DB {
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment