Documentation

Overview

    Package testfixture helps you bootstrap test scenarios very effectively.

    Take a look at the

    NewFixture()
    

    function to learn how to use this package.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func GetTestFileAndFunc

    func GetTestFileAndFunc() string

      GetTestFileAndFunc returns the file and function of the first _test.go file to appear in the stack and returns it in this schema (without the line breaks)

      (see function github.com/fabric8-services/fabric8-wit/test/testfixture_test.TestGetGetTestFileAndFunc in test/testfixture/testfixture_test.go)

      The result can be used to augment entities so that we always can tell which test created an entity that is a left-over and not cleaned up for example.

      Types

      type CustomizeAreaFunc

      type CustomizeAreaFunc CustomizeEntityFunc

        CustomizeAreaFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Areas() recipe-function.

        func PlaceAreaUnderRootArea

        func PlaceAreaUnderRootArea() CustomizeAreaFunc

          PlaceAreaUnderRootArea when asking for more than one area, all but the first one will be placed under the first area (aka root area).

          func SetAreaNames

          func SetAreaNames(names ...string) CustomizeAreaFunc

            SetAreaNames takes the given names and uses them during creation of areas. The length of requested areas and the number of names must match or the NewFixture call will return an error.

            type CustomizeCodebaseFunc

            type CustomizeCodebaseFunc CustomizeEntityFunc

              CustomizeCodebaseFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Codebases() recipe-function.

              type CustomizeCommentFunc

              type CustomizeCommentFunc CustomizeEntityFunc

                CustomizeCommentFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Comments() recipe-function.

                type CustomizeEntityFunc

                type CustomizeEntityFunc func(fxt *TestFixture, idx int) error

                  A CustomizeEntityFunc acts as a generic function to the various recipe-functions (e.g. Identities(), Spaces(), etc.). The current test fixture is given with the fxt argument and the position of the object that will be created next is indicated by the index idx. That index can be used to look up e.g. a space with

                  s := fxt.Spaces[idx]
                  

                  That space s will be a ready-to-create space object on that you can modify to your liking.

                  Notice that when you lookup objects in the test fixture, you can only safely access those object on which the entity depends, because those are guaranteed to be already created. For example when you try to access a work item type from a customize-entity-function, it will not be very useful:

                  NewFixture(db, WorkItemTypes(1), Spaces(1, func(fxt *TestFixture, idx int) error{
                      fmt.Println(fxt.WorkItemType[0].ID) // WARNING: not yet set
                      return nil
                  }))
                  

                  On the other hand, you can safely lookup the space ID when you're in the customize-entity-function for a work item:

                  NewFixture(db, WorkItem(1, func(fxt *TestFixture, idx int) error{
                      fmt.Println(fxt.Space[0].ID) // safe to access
                      return nil
                  }))
                  

                  Notice that you can do all kinds of distribution related functions in a customize-entitiy-function. For example, you can control which identity owns a space or define what work item type each work item shall have. If not otherwise specified (e.g. as for WorkItemLinks()) we use a straight forward approach. So for example if you write

                  NewFixture(t, db, Identities(10), Spaces(100))
                  

                  then we will create 10 identites and 100 spaces and the owner of all spaces will be identified with the ID of the first identity:

                  fxt.Identities[0].ID
                  

                  If you want a different distribution, you can create your own customize- entitiy-function (see Identities() for an example).

                  If you for some error reason you want your test fixture creation to fail you can use the fxt.T test instance:

                  NewFixture(db, Identities(100, func(fxt *TestFixture, idx int) error{
                      return errors.New("some test failure reason")
                  }))
                  

                  type CustomizeIdentityFunc

                  type CustomizeIdentityFunc CustomizeEntityFunc

                    CustomizeIdentityFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Identites() recipe-function.

                    func SetIdentityUsernames

                    func SetIdentityUsernames(usernames ...string) CustomizeIdentityFunc

                      SetIdentityUsernames takes the given usernames and uses them during creation of identities. The length of requested work item types and the number of usernames must match or the NewFixture call will return an error.

                      type CustomizeIterationFunc

                      type CustomizeIterationFunc CustomizeEntityFunc

                        CustomizeIterationFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Iterations() recipe-function.

                        func PlaceIterationUnderRootIteration

                        func PlaceIterationUnderRootIteration() CustomizeIterationFunc

                          PlaceIterationUnderRootIteration when asking for more than one iteration, all but the first one will be placed under the first iteration (aka root iteration).

                          func SetIterationNames

                          func SetIterationNames(names ...string) CustomizeIterationFunc

                            SetIterationNames takes the given names and uses them during creation of iterations. The length of requested iterations and the number of names must match or the NewFixture call will return an error.

                            func UserActive

                            func UserActive(active bool) CustomizeIterationFunc

                              UserActive ensures that all created iterations have the given user activation state

                              type CustomizeLabelFunc

                              type CustomizeLabelFunc CustomizeEntityFunc

                                CustomizeLabelFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Labels() recipe-function.

                                func SetLabelNames

                                func SetLabelNames(names ...string) CustomizeLabelFunc

                                  SetLabelNames takes the given names and uses them during creation of labels. The length of requested labels and the number of names must match or the NewFixture call will return an error.

                                  type CustomizeQueryFunc

                                  type CustomizeQueryFunc CustomizeEntityFunc

                                    CustomizeQueryFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Queries() recipe-function.

                                    func SetQueryTitles

                                    func SetQueryTitles(titles ...string) CustomizeQueryFunc

                                      SetQueryTitles takes the given titles and uses them during creation of queries. The length of requested queries and the number of titles must match or the NewFixture call will return an error.

                                      type CustomizeSpaceFunc

                                      type CustomizeSpaceFunc CustomizeEntityFunc

                                        CustomizeSpaceFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Spaces() recipe-function.

                                        type CustomizeSpaceTemplateFunc

                                        type CustomizeSpaceTemplateFunc CustomizeEntityFunc

                                          CustomizeSpaceTemplateFunc is directly compatible with CustomizeEntityFunc but it can only be used for the SpaceTemplates() recipe-function.

                                          func SetSpaceTemplateNames

                                          func SetSpaceTemplateNames(names ...string) CustomizeSpaceTemplateFunc

                                            SetSpaceTemplateNames takes the given names and uses them during creation of space templates. The length of requested space templates and the number of names must match or the NewFixture call will return an error.

                                            type CustomizeTrackerFunc

                                            type CustomizeTrackerFunc CustomizeEntityFunc

                                              CustomizeTrackerFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Trackers() recipe-function.

                                              type CustomizeTrackerQueriesFunc

                                              type CustomizeTrackerQueriesFunc CustomizeEntityFunc

                                                CustomizeTrackerQueriesFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Trackers() recipe-function.

                                                type CustomizeUserFunc

                                                type CustomizeUserFunc CustomizeEntityFunc

                                                  CustomizeUserFunc is directly compatible with CustomizeEntityFunc but it can only be used for the Users() recipe-function.

                                                  type CustomizeWorkItemBoardFunc

                                                  type CustomizeWorkItemBoardFunc CustomizeEntityFunc

                                                    CustomizeWorkItemBoardFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItemBoards() recipe-function.

                                                    type CustomizeWorkItemFunc

                                                    type CustomizeWorkItemFunc CustomizeEntityFunc

                                                      CustomizeWorkItemFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItems() recipe-function.

                                                      func SetWorkItemField

                                                      func SetWorkItemField(fieldName string, values ...interface{}) CustomizeWorkItemFunc

                                                        SetWorkItemField takes the given values and uses them during creation of work items to set field values. The length of requested work items and the number of values must match or the NewFixture call will return an error.

                                                        func SetWorkItemTitles

                                                        func SetWorkItemTitles(titleStrings ...interface{}) CustomizeWorkItemFunc

                                                          SetWorkItemTitles takes the given titles and uses them during creation of work items. The length of requested work items and the number of titles must match or the NewFixture call will return an error.

                                                          type CustomizeWorkItemLinkFunc

                                                          type CustomizeWorkItemLinkFunc CustomizeEntityFunc

                                                            CustomizeWorkItemLinkFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItemLinks() recipe-function.

                                                            func BuildLinks(links ...Link) CustomizeWorkItemLinkFunc

                                                              BuildLinks is best explained with an example: the function takes `Link` objects, which are meant to be constructed using either `L` or `LinkChain`. Before you would have to build a gigantic `switch` statement even for the simplest of links.

                                                              The following example shows how you can create two links chains that create these links `A->B, B->C, D->E, E->F, F->G`:

                                                              chain1 := tf.LinkChain("A", "B", "C")
                                                              chain2 := tf.LinkChain("D", "E", "F", "G")
                                                              fxt := tf.NewTestFixture(t, s.DB,
                                                              	tf.WorkItemLinkTypes(1, tf.SetTopologies(link.TopologyDependency)),
                                                              	tf.WorkItems(7, tf.SetWorkItemTitles("A", "B", "C", "D", "E", "F", "G")),
                                                              	tf.WorkItemLinksCustom(5, tf.BuildLinks(append(chain1, chain2...)...)),
                                                              )
                                                              

                                                              type CustomizeWorkItemLinkTypeFunc

                                                              type CustomizeWorkItemLinkTypeFunc CustomizeEntityFunc

                                                                CustomizeWorkItemLinkTypeFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItemLinkTypes() recipe-function.

                                                                func SetTopologies

                                                                func SetTopologies(topologies ...link.Topology) CustomizeWorkItemLinkTypeFunc

                                                                  SetTopologies takes the given topologies and uses them during creation of work item link types. The length of requested work item link types and the number of topologies must match or the NewFixture call will return an error.

                                                                  func SetWorkItemLinkTypeNames

                                                                  func SetWorkItemLinkTypeNames(names ...string) CustomizeWorkItemLinkTypeFunc

                                                                    SetWorkItemLinkTypeNames takes the given names and uses them during creation of work item link types. The length of requested work item link types and the number of names must match or the NewFixture call will return an error.

                                                                    type CustomizeWorkItemTypeFunc

                                                                    type CustomizeWorkItemTypeFunc CustomizeEntityFunc

                                                                      CustomizeWorkItemTypeFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItemTypes() recipe-function.

                                                                      func SetWorkItemTypeNames

                                                                      func SetWorkItemTypeNames(names ...string) CustomizeWorkItemTypeFunc

                                                                        SetWorkItemTypeNames takes the given names and uses them during creation of work item types. The length of requested work item types and the number of names must match or the NewFixture call will return an error.

                                                                        type CustomizeWorkItemTypeGroupFunc

                                                                        type CustomizeWorkItemTypeGroupFunc CustomizeEntityFunc

                                                                          CustomizeWorkItemTypeGroupFunc is directly compatible with CustomizeEntityFunc but it can only be used for the WorkItemTypeGroups() recipe-function.

                                                                          type Link struct {
                                                                          	SourceTitle   string
                                                                          	TargetTitle   string
                                                                          	LinkTypeTitle string
                                                                          }

                                                                            Link is a helper struct to construct a link from two work item titles (instead of the work item IDs). It is mainly used by the `L`, `LinkChain` and `BuildLinks` functions.

                                                                            func L

                                                                            func L(SourceTitle string, TargetTitle string, LinkTypeTitle ...string) Link

                                                                              L constructs and individual link from the source and target work item titles with an optional link type name.

                                                                              func LinkChain

                                                                              func LinkChain(workItemTitles ...string) []Link

                                                                                LinkChain creates Link objects between each of the given work item as specified by their title.

                                                                                For example, `LinkChain("A", "B", "C", "D")“ will create these links `A->B`, `B->C`, and `C-D`.

                                                                                type RecipeFunction

                                                                                type RecipeFunction func(fxt *TestFixture) error

                                                                                  A RecipeFunction tells the test fixture to create n objects of a given kind. You can pass in customize-entity-functions in order to manipulate the objects before they get created.

                                                                                  func Areas

                                                                                  func Areas(n int, fns ...CustomizeAreaFunc) RecipeFunction

                                                                                    Areas tells the test fixture to create at least n area objects. See also the Identities() function for more general information on n and fns.

                                                                                    When called in NewFixture() this function will call also call

                                                                                    Spaces(1)
                                                                                    

                                                                                    but with NewFixtureIsolated(), no other objects will be created.

                                                                                    func Codebases

                                                                                    func Codebases(n int, fns ...CustomizeCodebaseFunc) RecipeFunction

                                                                                      Codebases tells the test fixture to create at least n codebase objects. See also the Identities() function for more general information on n and fns.

                                                                                      When called in NewFixture() this function will call also call

                                                                                      Spaces(1)
                                                                                      

                                                                                      but with NewFixtureIsolated(), no other objects will be created.

                                                                                      func Comments

                                                                                      func Comments(n int, fns ...CustomizeWorkItemFunc) RecipeFunction

                                                                                        Comments tells the test fixture to create at least n comment objects. See also the Identities() function for more general information on n and fns.

                                                                                        When called in NewFixture() this function will call also call

                                                                                        Identities(1)
                                                                                        WorkItems(1)
                                                                                        

                                                                                        but with NewFixtureIsolated(), no other objects will be created.

                                                                                        func CreateWorkItemEnvironment

                                                                                        func CreateWorkItemEnvironment() RecipeFunction

                                                                                          CreateWorkItemEnvironment returns a higher level recipe function that contains a little bit more business logic compared to the plain recipe functions that only set up dependencies according to database needs. In this particular case, we create a root iteration and root area and make additional areas be child of the root instances.

                                                                                          func Identities

                                                                                          func Identities(n int, fns ...CustomizeIdentityFunc) RecipeFunction

                                                                                            Identities tells the test fixture to create at least n identity objects. See also the Users() function for more general information on n and fns. When called in NewFixture() this function call will also call

                                                                                            Users(1)
                                                                                            

                                                                                            but with NewFixtureIsolated(), no other objects will be created.

                                                                                            func Iterations

                                                                                            func Iterations(n int, fns ...CustomizeIterationFunc) RecipeFunction

                                                                                              Iterations tells the test fixture to create at least n iteration objects. See also the Identities() function for more general information on n and fns.

                                                                                              When called in NewFixture() this function will call also call

                                                                                              Spaces(1)
                                                                                              

                                                                                              but with NewFixtureIsolated(), no other objects will be created.

                                                                                              func Labels

                                                                                              func Labels(n int, fns ...CustomizeLabelFunc) RecipeFunction

                                                                                                Labels tells the test fixture to create at least n label objects. See also the Identities() function for more general information on n and fns.

                                                                                                When called in NewFixture() this function will call also call

                                                                                                Spaces(1)
                                                                                                

                                                                                                but with NewFixtureIsolated(), no other objects will be created.

                                                                                                func Queries

                                                                                                func Queries(n int, fns ...CustomizeQueryFunc) RecipeFunction

                                                                                                  Queries tells the test fixture to create at least n Query objects. See also the Identities() function for more general information on n and fns.

                                                                                                  When called in NewFixture() this function will call also call

                                                                                                  Spaces(1)
                                                                                                  

                                                                                                  but with NewFixtureIsolated(), no other objects will be created.

                                                                                                  func SpaceTemplates

                                                                                                  func SpaceTemplates(n int, fns ...CustomizeSpaceTemplateFunc) RecipeFunction

                                                                                                    SpaceTemplates tells the test fixture to create at least n space template objects. See also the Identities() function for more general information on n and fns.

                                                                                                    func Spaces

                                                                                                    func Spaces(n int, fns ...CustomizeSpaceFunc) RecipeFunction

                                                                                                      Spaces tells the test fixture to create at least n space objects. See also the Identities() function for more general information on n and fns.

                                                                                                      When called in NewFixture() this function will call also call

                                                                                                      Identities(1)
                                                                                                      SpaceTemplates(1)
                                                                                                      

                                                                                                      but with NewFixtureIsolated(), no other objects will be created.

                                                                                                      func TrackerQueries

                                                                                                      func TrackerQueries(n int, fns ...CustomizeTrackerQueriesFunc) RecipeFunction

                                                                                                        TrackerQueries tells the test fixture to create at least n tracker objects. See also the Identities() function for more general information on n and fns.

                                                                                                        When called in NewFixture() this function will call also call

                                                                                                        Spaces(1)
                                                                                                        

                                                                                                        but with NewFixtureIsolated(), no other objects will be created.

                                                                                                        func Trackers

                                                                                                        func Trackers(n int, fns ...CustomizeTrackerFunc) RecipeFunction

                                                                                                          Trackers tells the test fixture to create at least n tracker objects. See also the Identities() function for more general information on n and fns.

                                                                                                          When called in NewFixture() this function will call also call

                                                                                                          Spaces(1)
                                                                                                          

                                                                                                          but with NewFixtureIsolated(), no other objects will be created.

                                                                                                          func Users

                                                                                                          func Users(n int, fns ...CustomizeUserFunc) RecipeFunction

                                                                                                            Users tells the test fixture to create at least n user objects.

                                                                                                            If called multiple times with differently n's, the biggest n wins. All customize-entitiy-functions fns from all calls will be respected when creating the test fixture.

                                                                                                            Here's an example how you can create 10 users and give them a numbered fullname like "John Doe 0", "John Doe 1", and so forth:

                                                                                                            Users(10, func(fxt *TestFixture, idx int) error{
                                                                                                                fxt.Users[idx].FullName = "Jane Doe " + strconv.FormatInt(idx, 10)
                                                                                                                return nil
                                                                                                            })
                                                                                                            

                                                                                                            Notice that the index idx goes from 0 to n-1 and that you have to manually lookup the object from the test fixture. The User object referenced by

                                                                                                            fxt.Users[idx]
                                                                                                            

                                                                                                            is guaranteed to be ready to be used for creation. That means, you don't necessarily have to touch it to avoid unique key violation for example. This is totally optional.

                                                                                                            func WorkItemBoards

                                                                                                            func WorkItemBoards(n int, fns ...CustomizeWorkItemBoardFunc) RecipeFunction

                                                                                                              WorkItemBoards tells the test fixture to create at least n work item boards objects. See also the Identities() function for more general information on n and fns.

                                                                                                              When called in NewFixture() this function will also call

                                                                                                              WorkItemTypeGroups(1)
                                                                                                              

                                                                                                              but with NewFixtureIsolated(), no other objects will be created.

                                                                                                              func WorkItemLinkTypes

                                                                                                              func WorkItemLinkTypes(n int, fns ...CustomizeWorkItemLinkTypeFunc) RecipeFunction

                                                                                                                WorkItemLinkTypes tells the test fixture to create at least n work item link type objects. See also the Identities() function for more general information on n and fns.

                                                                                                                When called in NewFixture() this function will call also call

                                                                                                                SpaceTemplates(1)
                                                                                                                

                                                                                                                but with NewFixtureIsolated(), no other objects will be created.

                                                                                                                We've created these helper functions that you should have a look at if you want to implement your own re-usable customize-entity-functions:

                                                                                                                SetTopologies(topology ...link.Topology)
                                                                                                                

                                                                                                                The topology functions above are neat because you don't have to write a full function function yourself.

                                                                                                                By default a call to

                                                                                                                WorkItemLinkTypes(1)
                                                                                                                

                                                                                                                equals

                                                                                                                WorkItemLinkTypes(1, SetTopologies(link.TopologyTree))
                                                                                                                

                                                                                                                because we automatically set the topology for each link type to be "tree".

                                                                                                                func WorkItemLinks(n int, fns ...CustomizeWorkItemLinkFunc) RecipeFunction

                                                                                                                  WorkItemLinks tells the test fixture to create at least n work item link objects. See also the Identities() function for more general information on n and fns.

                                                                                                                  When called in NewFixture() this function will call also call

                                                                                                                  WorkItemLinkTypes(1)
                                                                                                                  WorkItems(2*n)
                                                                                                                  

                                                                                                                  but with NewFixtureIsolated(), no other objects will be created.

                                                                                                                  Notice, that we will create two times the number of work items of your requested links. The way those links will be created can for sure be influenced using a customize-entity-function; but by default we create each link between two distinct work items. That means, no link will include the same work item.

                                                                                                                  func WorkItemLinksCustom

                                                                                                                  func WorkItemLinksCustom(n int, fns ...CustomizeWorkItemLinkFunc) RecipeFunction

                                                                                                                    WorkItemLinksCustom behaves the same ways as WorkItemLinks but it makes no assumption on the number of work items that are going to be created. That means you can request and arbitrary number of links but you are also responsible of creating the the work items that you want to use in your links.

                                                                                                                    NOTE: Normal WorkItemLinks creates twice the amount of work items as links.

                                                                                                                    func WorkItemTypeGroups

                                                                                                                    func WorkItemTypeGroups(n int, fns ...CustomizeWorkItemTypeGroupFunc) RecipeFunction

                                                                                                                      WorkItemTypeGroups tells the test fixture to create at least n work item type group objects. See also the Identities() function for more general information on n and fns.

                                                                                                                      When called in NewFixture() this function will call also call

                                                                                                                      WorkItemTypes(1)
                                                                                                                      

                                                                                                                      but with NewFixtureIsolated(), no other objects will be created.

                                                                                                                      func WorkItemTypes

                                                                                                                      func WorkItemTypes(n int, fns ...CustomizeWorkItemTypeFunc) RecipeFunction

                                                                                                                        WorkItemTypes tells the test fixture to create at least n work item type objects. See also the Identities() function for more general information on n and fns.

                                                                                                                        When called in NewFixture() this function will call also call

                                                                                                                        SpaceTemplates(1)
                                                                                                                        

                                                                                                                        but with NewFixtureIsolated(), no other objects will be created.

                                                                                                                        The work item type that we create for each of the n instances is always the same and it is compatible with the planner item work item type by.

                                                                                                                        func WorkItems

                                                                                                                        func WorkItems(n int, fns ...CustomizeWorkItemFunc) RecipeFunction

                                                                                                                          WorkItems tells the test fixture to create at least n work item objects. See also the Identities() function for more general information on n and fns.

                                                                                                                          When called in NewFixture() this function will call also call

                                                                                                                          Spaces(1)
                                                                                                                          WorkItemTypes(1)
                                                                                                                          Identities(1)
                                                                                                                          

                                                                                                                          but with NewFixtureIsolated(), no other objects will be created.

                                                                                                                          Notice that the Number field of a work item is only set after the work item has been created, so any changes you make to

                                                                                                                          fxt.WorkItems[idx].Number
                                                                                                                          

                                                                                                                          will have no effect.

                                                                                                                          type TestFixture

                                                                                                                          type TestFixture struct {
                                                                                                                          	Users              []*account.User                // Users (if any) that were created for this test fixture.
                                                                                                                          	Identities         []*account.Identity            // Identities (if any) that were created for this test fixture.
                                                                                                                          	Iterations         []*iteration.Iteration         // Iterations (if any) that were created for this test fixture.
                                                                                                                          	Areas              []*area.Area                   // Areas (if any) that were created for this test fixture.
                                                                                                                          	Spaces             []*space.Space                 // Spaces (if any) that were created for this test fixture.
                                                                                                                          	Codebases          []*codebase.Codebase           // Codebases (if any) that were created for this test fixture.
                                                                                                                          	WorkItems          []*workitem.WorkItem           // Work items (if any) that were created for this test fixture.
                                                                                                                          	Comments           []*comment.Comment             // Comments (if any) that were created for this test fixture.
                                                                                                                          	WorkItemTypes      []*workitem.WorkItemType       // Work item types (if any) that were created for this test fixture.
                                                                                                                          	WorkItemLinkTypes  []*link.WorkItemLinkType       // Work item link types (if any) that were created for this test fixture.
                                                                                                                          	WorkItemLinks      []*link.WorkItemLink           // Work item links (if any) that were created for this test fixture.
                                                                                                                          	Labels             []*label.Label                 // Labels (if any) that were created for this test fixture.
                                                                                                                          	Trackers           []*remoteworkitem.Tracker      // Remote work item tracker (if any) that were created for this test fixture.
                                                                                                                          	TrackerQueries     []*remoteworkitem.TrackerQuery // Remote work item tracker query (if any) that were created for this test fixture.
                                                                                                                          	Queries            []*query.Query                 // Queries (if any) that were created for this test fixture.
                                                                                                                          	SpaceTemplates     []*spacetemplate.SpaceTemplate // Space templates (if any) that were created for this test fixture.
                                                                                                                          	WorkItemTypeGroups []*workitem.WorkItemTypeGroup  // Work item types groups (if any) that were created for this test fixture.
                                                                                                                          	WorkItemBoards     []*workitem.Board              // Work item boards (if any) that were created for this test fixture.
                                                                                                                          	// contains filtered or unexported fields
                                                                                                                          }

                                                                                                                            A TestFixture object is the result of a call to

                                                                                                                            NewFixture()
                                                                                                                            

                                                                                                                            or

                                                                                                                            NewFixtureIsolated()
                                                                                                                            

                                                                                                                            Don't create one on your own!

                                                                                                                            func NewFixture

                                                                                                                            func NewFixture(db *gorm.DB, recipeFuncs ...RecipeFunction) (*TestFixture, error)

                                                                                                                              NewFixture will create a test fixture by executing the recipies from the given recipe functions. If recipeFuncs is empty, nothing will happen.

                                                                                                                              For example

                                                                                                                              NewFixture(db, Comments(100))
                                                                                                                              

                                                                                                                              will create a work item (and everything required in order to create it) and author 100 comments for it. They will all be created by the same user if you don't tell the system to do it differently. For example, to create 100 comments from 100 different users we can do the following:

                                                                                                                              NewFixture(db, Identities(100), Comments(100, func(fxt *TestFixture, idx int) error{
                                                                                                                                  fxt.Comments[idx].Creator = fxt.Identities[idx].ID
                                                                                                                                  return nil
                                                                                                                              }))
                                                                                                                              

                                                                                                                              That will create 100 identities and 100 comments and for each comment we're using the ID of one of the identities that have been created earlier. There's one important observation to make with this example: there's an order to how entities get created in the test fixture. That order is basically defined by the number of dependencies that each entity has. For example an identity has no dependency, so it will be created first and then can be accessed safely by any of the other entity creation functions. A comment for example depends on a work item which itself depends on a work item type and a space. The NewFixture function does take care of recursively resolving those dependcies first.

                                                                                                                              If you just want to create 100 identities and 100 work items but don't care about resolving the dependencies automatically you can create the entities in isolation:

                                                                                                                              NewFixtureIsolated(db, Identities(100), Comments(100, func(fxt *TestFixture, idx int) error{
                                                                                                                                  fxt.Comments[idx].Creator = fxt.Identities[idx].ID
                                                                                                                                  fxt.Comments[idx].ParentID = someExistingWorkItemID
                                                                                                                                  return nil
                                                                                                                              }))
                                                                                                                              

                                                                                                                              Notice that I manually have to specify the ParentID of the work comment then because we cannot automatically resolve to which work item we will attach the comment.

                                                                                                                              func NewFixtureIsolated

                                                                                                                              func NewFixtureIsolated(db *gorm.DB, setupFuncs ...RecipeFunction) (*TestFixture, error)

                                                                                                                                NewFixtureIsolated will create a test fixture by executing the recipies from the given recipe functions. If recipeFuncs is empty, nothing will happen.

                                                                                                                                The difference to the normal NewFixture function is that we will only create those object that where specified in the recipeFuncs. We will not create any object that is normally demanded by an object. For example, if you call

                                                                                                                                NewFixture(t, db, WorkItems(1))
                                                                                                                                

                                                                                                                                you would (apart from other objects) get at least one work item AND a work item type because that is needed to create a work item. With

                                                                                                                                NewFixtureIsolated(t, db, Comments(2), WorkItems(1))
                                                                                                                                

                                                                                                                                on the other hand, we will only create a work item, two comments for it, and nothing more. And for sure your test will fail if you do that because you need to specify a space ID and a work item type ID for the created work item:

                                                                                                                                NewFixtureIsolated(db, Comments(2), WorkItems(1, func(fxt *TestFixture, idx int) error{
                                                                                                                                  fxt.WorkItems[idx].SpaceID = someExistingSpaceID
                                                                                                                                  fxt.WorkItems[idx].WorkItemType = someExistingWorkItemTypeID
                                                                                                                                  return nil
                                                                                                                                }))
                                                                                                                                

                                                                                                                                func NewTestFixture

                                                                                                                                func NewTestFixture(t testing.TB, db *gorm.DB, recipeFuncs ...RecipeFunction) *TestFixture

                                                                                                                                  NewTestFixture does the same as NewFixture except that it automatically fails the given test if the fixture could not be created correctly.

                                                                                                                                  func (*TestFixture) AreaByName

                                                                                                                                  func (fxt *TestFixture) AreaByName(name string, spaceID ...uuid.UUID) *area.Area

                                                                                                                                    AreaByName returns the first area that has the given name (if any). If you have areas with the same name in different spaces you can also pass in one space ID to filter by space as well.

                                                                                                                                    func (*TestFixture) Check

                                                                                                                                    func (fxt *TestFixture) Check() error

                                                                                                                                      Check runs all check functions that each recipe-function has registered to check that the amount of objects has been created that were demanded in the recipe function.

                                                                                                                                      In this example

                                                                                                                                      fxt, _:= NewFixture(db, WorkItems(2))
                                                                                                                                      err = fxt.Check()
                                                                                                                                      

                                                                                                                                      err will only be nil if at least two work items have been created and all of the dependencies that a work item requires. Look into the documentation of each recipe-function to find out what dependencies each entity has.

                                                                                                                                      Notice, that check is called at the end of NewFixture() and its derivatives, so if you don't mess with the fixture after it was created, there's no need to call Check() again.

                                                                                                                                      func (*TestFixture) IdentityByUsername

                                                                                                                                      func (fxt *TestFixture) IdentityByUsername(username string) *account.Identity

                                                                                                                                        IdentityByUsername returns the first identity that has the given username (if any).

                                                                                                                                        func (*TestFixture) IterationByName

                                                                                                                                        func (fxt *TestFixture) IterationByName(name string, spaceID ...uuid.UUID) *iteration.Iteration

                                                                                                                                          IterationByName returns the first iteration that has the given name (if any). If you have iterations with the same name in different spaces you can also pass in one space ID to filter by space as well.

                                                                                                                                          func (*TestFixture) LabelByName

                                                                                                                                          func (fxt *TestFixture) LabelByName(name string, spaceID ...uuid.UUID) *label.Label

                                                                                                                                            LabelByName returns the first label that has the given name (if any). If you have labels with the same name in different spaces you can also pass in one space ID to filter by space as well.

                                                                                                                                            func (*TestFixture) QueryByTitle

                                                                                                                                            func (fxt *TestFixture) QueryByTitle(title string, spaceID ...uuid.UUID) *query.Query

                                                                                                                                              QueryByTitle returns the first query that has the given title (if any). If you have queries with the same title in different spaces you can also pass in one space ID to filter by space as well.

                                                                                                                                              func (*TestFixture) SpaceTemplateByName

                                                                                                                                              func (fxt *TestFixture) SpaceTemplateByName(name string) *spacetemplate.SpaceTemplate

                                                                                                                                                SpaceTemplateByName returns the first space template that has the given name (if any).

                                                                                                                                                func (*TestFixture) WorkItemByID

                                                                                                                                                func (fxt *TestFixture) WorkItemByID(ID uuid.UUID) *workitem.WorkItem

                                                                                                                                                  WorkItemByID returns the first work item that has the given ID (if any).

                                                                                                                                                  func (*TestFixture) WorkItemByTitle

                                                                                                                                                  func (fxt *TestFixture) WorkItemByTitle(title string, spaceID ...uuid.UUID) *workitem.WorkItem

                                                                                                                                                    WorkItemByTitle returns the first work item that has the given title (if any). If you have work items with the same title in different spaces you can also pass in one space ID to filter by space as well.

                                                                                                                                                    func (*TestFixture) WorkItemLinkTypeByName

                                                                                                                                                    func (fxt *TestFixture) WorkItemLinkTypeByName(name string, spaceTemplateID ...uuid.UUID) *link.WorkItemLinkType

                                                                                                                                                      WorkItemLinkTypeByName returns the first work item link type that has the given name (if any). If you have work item link types with the same name in different space templates you can also pass in one space template ID to filter by space template as well.

                                                                                                                                                      func (*TestFixture) WorkItemTypeByID

                                                                                                                                                      func (fxt *TestFixture) WorkItemTypeByID(id uuid.UUID) *workitem.WorkItemType

                                                                                                                                                        WorkItemTypeByID returns the work item type that has the given ID (if any).

                                                                                                                                                        func (*TestFixture) WorkItemTypeByName

                                                                                                                                                        func (fxt *TestFixture) WorkItemTypeByName(name string, spaceTemplateID ...uuid.UUID) *workitem.WorkItemType

                                                                                                                                                          WorkItemTypeByName returns the first work item type that has the given name (if any). If you have work item types with the same name in different space templates you can also pass in one space template ID to filter by space template as well.