Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
Created March 10, 2017 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslakknutsen/aa843414f2c9055573246ca145ff39f6 to your computer and use it in GitHub Desktop.
Save aslakknutsen/aa843414f2c9055573246ca145ff39f6 to your computer and use it in GitHub Desktop.
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