gotestrail

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 26 Imported by: 0

README

Go TestRail

Build Status Go Report Card Docs License

Go Client for TestRail API.

Usage

Direct
import "github.com/grokify/gotestrail"

func main() {
    client, err := gotestrail.NewClient("https://mydomain.testrail.io/", "myusername", "mypassword")
}
GoAuth Credentials File
.goauth.json

Create a file, e.g. .goauth.json to contain your credentials with GoAuth, e.g:

{
    "credentials": {
        "TESTRAIL": {
            "type": "basic",
            "service": "testrail",
            "basic": {
                "serverURL": "https://<mydomain>.testrail.io/",
                "username": "<myusername>",
                "password": "<mypassword>"
            }
        }
    }
}
Code
import "github.com/grokify/gotestrail"

func main() {
    // ... get `goauth.Credentials`
    client, err := gotestrail.NewClientFromGoauthCredentials(creds) // `creds` is a `goauth.Credentials{}`
}
  1. github.com/educlos/testrail
  2. github.com/qba73/tr

Documentation

Index

Constants

View Source
const (
	IndexPath                   = "index.php?"
	APIPathCasesGet             = "/api/v2/get_cases/"
	APIPathCasesGetProjectID    = "/api/v2/get_cases/%d&limit=%d&offset=%d"
	APIPathCaseFieldsGet        = "/api/v2/get_case_fields/"
	APIPathCaseTypesGet         = "/api/v2/get_case_types/"
	APIPathSectionsGet          = "/api/v2/get_sections/"
	APIPathSectionsGetProjectID = "/api/v2/get_sections/%d&limit=%d&offset=%d"

	LimitMax uint = 250

	QueryParamLimit     = "limit"
	QueryParamOffset    = "offset"
	QueryParamSectionID = "section_id"
	QueryParamSuiteID   = "suite_id"

	SlugCase     = "case"
	SlugCaseType = "case_type"
	SlugSection  = "section"
)

Variables

View Source
var ErrResponseCannotBeNil = errors.New("response cannot be nil")

Functions

func BuildAPIURL

func BuildAPIURL(baseURL, apiPath string, id, limit, offset int, qry url.Values) string

func BuildFuncRespSavePages added in v0.5.0

func BuildFuncRespSavePages(dir string, projectID uint) func(qry url.Values, respBody []byte) error

func ProcessCaseAPIResponse added in v0.5.0

func ProcessCaseAPIResponse(r *http.Response, fn func(b []byte) error) (string, []byte, error)

ProcessCaseAPIResponse processes a http.Response and returns a next page URL along with body bytes.

Types

type Case

type Case struct {
	ID                   uint    `json:"id"`
	Title                string  `json:"title"`
	CreatedBy            uint    `json:"created_by"`
	CreatedOn            uint    `json:"created_on"`
	CustomAutomationType *int    `json:"custom_automation_type"`
	DisplayOrder         *int    `json:"display_order"`
	Estimate             *string `json:"estimate"`
	EstimateForecast     *string `json:"estimate_forecast"`
	UpdatedBy            uint    `json:"updated_by"`
	UpdatedOn            uint    `json:"updated_on"`
	IsDeleted            *int    `json:"is_deleted"`
	MilestoneID          *uint   `json:"milestone_id"`
	PriorityID           *uint   `json:"priority_id"`
	Refs                 *string `json:"refs"`
	SectionID            *uint   `json:"section_id"`
	SuiteID              *uint   `json:"suite_id"`
	TemplateID           *uint   `json:"template_id"`
	TypeID               *uint   `json:"type_id"`
	XLineageSectionIDs   string  `json:"x_lineage_section_ids"`
}

func (Case) MatchFunc

func (c Case) MatchFunc(fn FuncCaseMatch) bool

func (Case) RefsContains

func (c Case) RefsContains(s string) bool

type CaseAPI added in v0.2.0

type CaseAPI struct {
	// contains filtered or unexported fields
}

func NewCaseAPI added in v0.2.0

func NewCaseAPI(client *Client) CaseAPI

func (CaseAPI) GetCaseSetAllFunc added in v0.5.0

func (api CaseAPI) GetCaseSetAllFunc(ctx context.Context, projectID uint, qry url.Values, fnResp func(qry url.Values, respBody []byte) error) (*CaseSet, error)

func (CaseAPI) GetCaseSetSectionsFunc added in v0.5.0

func (api CaseAPI) GetCaseSetSectionsFunc(ctx context.Context, projectID uint, sectionIDs []uint, fnResp func(qry url.Values, respBody []byte) error) error

func (CaseAPI) GetCases added in v0.2.0

func (api CaseAPI) GetCases(ctx context.Context, projectID, limit, offset int, qry url.Values, parseResponse bool) (*GetCasesResponse, []byte, *http.Response, error)

func (CaseAPI) GetWriteFileCaseSetAll added in v0.4.0

func (api CaseAPI) GetWriteFileCaseSetAll(ctx context.Context, filename string, perm os.FileMode, prefix, indent string, projectID uint, qry url.Values) (*CaseSet, error)

type CaseField added in v0.5.0

type CaseField struct {
	ID         int               `json:"id"`
	IsActive   bool              `json:"is_active"`
	Name       string            `json:"name"`
	SystemName string            `json:"system_name"`
	Label      string            `json:"label"`
	Configs    []CaseFieldConfig `json:"configs"`
}

type CaseFieldAPI added in v0.5.0

type CaseFieldAPI struct {
	// contains filtered or unexported fields
}

func NewCaseFieldAPI added in v0.5.0

func NewCaseFieldAPI(client *Client) CaseFieldAPI

func (CaseFieldAPI) GetCaseFields added in v0.5.0

func (api CaseFieldAPI) GetCaseFields(ctx context.Context) (CaseFields, *http.Response, error)

type CaseFieldConfig added in v0.5.0

type CaseFieldConfig struct {
	Context CaseFieldContext       `json:"context"`
	ID      string                 `json:"id"`
	Options CaseFieldConfigOptions `json:"options"`
}

type CaseFieldConfigOptions added in v0.5.0

type CaseFieldConfigOptions struct {
	IsRequired bool   `json:"is_required"`
	Items      string `json:"items"`
	Format     string `json:"format"`
}

func (CaseFieldConfigOptions) ItemsMap added in v0.5.0

func (opts CaseFieldConfigOptions) ItemsMap() (map[uint]string, error)

type CaseFieldContext added in v0.5.0

type CaseFieldContext struct {
	IsGlobal   bool  `json:"is_global"`
	ProjectIDs []int `json:"project_ids"`
}

type CaseFieldSet added in v0.5.0

type CaseFieldSet struct {
	Data map[int]CaseField
}

type CaseFields added in v0.5.0

type CaseFields []CaseField

func ReadCaseFields added in v0.5.0

func ReadCaseFields(b []byte) (CaseFields, error)

func ReadFileCaseFields added in v0.5.0

func ReadFileCaseFields(filename string) (CaseFields, error)

type CaseSet

type CaseSet struct {
	Cases map[uint]Case `json:"cases"`
}

func NewCaseSet

func NewCaseSet() *CaseSet

func ReadFileCaseSet

func ReadFileCaseSet(filename string) (*CaseSet, error)

func (*CaseSet) Add

func (set *CaseSet) Add(c ...Case)

func (*CaseSet) FilterByFunc

func (set *CaseSet) FilterByFunc(fn FuncCaseMatch) *CaseSet

func (*CaseSet) Get

func (set *CaseSet) Get(caseID uint) (Case, bool)

func (*CaseSet) IDs

func (set *CaseSet) IDs() []uint

func (*CaseSet) IDsByFunc

func (set *CaseSet) IDsByFunc(fn FuncCaseMatch) []uint

func (*CaseSet) IDsBySection

func (set *CaseSet) IDsBySection(sectionID uint) []uint

func (*CaseSet) Len

func (set *CaseSet) Len() uint

func (*CaseSet) LineageStringsHistogram added in v0.5.0

func (set *CaseSet) LineageStringsHistogram(sectionSet *SectionSet, strSep string) (*histogram.Histogram, error)

func (*CaseSet) ReadDirJSONRawAPIs added in v0.5.0

func (set *CaseSet) ReadDirJSONRawAPIs(dir string, rx *regexp.Regexp) error

func (*CaseSet) ReadFileJSON added in v0.3.0

func (set *CaseSet) ReadFileJSON(filename string) error

func (*CaseSet) ReadFileJSONRawAPI added in v0.5.0

func (set *CaseSet) ReadFileJSONRawAPI(filename string) error

func (*CaseSet) ReadFileJSONRawAPIs added in v0.5.0

func (set *CaseSet) ReadFileJSONRawAPIs(filenames ...string) error

func (*CaseSet) ReadFileJSONs added in v0.5.0

func (set *CaseSet) ReadFileJSONs(filenames ...string) error

func (*CaseSet) WriteFileJSON

func (set *CaseSet) WriteFileJSON(filename string, perm os.FileMode, prefix, indent string) error

type CaseType

type CaseType struct {
	ID        uint   `json:"id"`
	Name      string `json:"name"`
	IsDefault bool   `json:"is_default"`
}

type CaseTypeAPI added in v0.2.0

type CaseTypeAPI struct {
	// contains filtered or unexported fields
}

func NewCaseTypeAPI added in v0.2.0

func NewCaseTypeAPI(client *Client) CaseTypeAPI

func (CaseTypeAPI) GetCaseTypes added in v0.2.0

func (api CaseTypeAPI) GetCaseTypes(ctx context.Context) ([]CaseType, *http.Response, error)

type CaseTypeSet

type CaseTypeSet struct {
	CaseTypes map[uint]CaseType `json:"caseTypes"`
}

func NewCaseTypeSet added in v0.3.0

func NewCaseTypeSet() *CaseTypeSet

func ReadFileCaseTypeSet added in v0.3.0

func ReadFileCaseTypeSet(filename string) (*CaseTypeSet, error)

func (*CaseTypeSet) Add

func (set *CaseTypeSet) Add(items ...CaseType)

func (*CaseTypeSet) ReadFileJSON added in v0.3.0

func (set *CaseTypeSet) ReadFileJSON(filename string) error

type Client

type Client struct {
	CaseAPI     CaseAPI
	CaseTypeAPI CaseTypeAPI
	SectionAPI  SectionAPI
	// contains filtered or unexported fields
}

func NewClient

func NewClient(serverURL, username, password string) (*Client, error)

func NewClientFromGoauthCredentials added in v0.4.0

func NewClientFromGoauthCredentials(creds goauth.Credentials) (*Client, error)

type FuncCaseMatch

type FuncCaseMatch func(c Case) bool

type GetCasesResponse

type GetCasesResponse struct {
	Offset uint   `json:"offset"`
	Limit  uint   `json:"limit"`
	Size   uint   `json:"size"`
	Links  Links  `json:"_links"`
	Cases  []Case `json:"cases"`
}

func ReadFileAPIResponseGetCases added in v0.5.0

func ReadFileAPIResponseGetCases(filename string) (*GetCasesResponse, error)

type GetSectionsResponse

type GetSectionsResponse struct {
	Offset   uint      `json:"offset"`
	Limit    uint      `json:"limit"`
	Size     uint      `json:"size"`
	Links    Links     `json:"_links"`
	Sections []Section `json:"sections"`
}
type Links struct {
	Next *string `json:"next"`
	Prev *string `json:"prev"`
}

type Metadata

type Metadata struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

type Metadatas

type Metadatas []Metadata

func (Metadatas) LineageIDsString added in v0.5.0

func (mds Metadatas) LineageIDsString() string

func (Metadatas) LineageIDsStrings added in v0.5.0

func (mds Metadatas) LineageIDsStrings() []string

type MultiSet

type MultiSet struct {
	CaseSet     *CaseSet     `json:"cases"`
	CaseTypeSet *CaseTypeSet `json:"caseTypes"`
	SectionSet  *SectionSet  `json:"sections"`
}

func NewMultiSet added in v0.3.0

func NewMultiSet() *MultiSet

func (*MultiSet) Lens added in v0.3.0

func (set *MultiSet) Lens() map[string]uint

type ResponsePagination added in v0.5.0

type ResponsePagination struct {
	Offset   int
	Limit    int
	Size     int
	LinkNext string
	LinkPrev string
}

ResponsePagination is a container for pagination when only pagination parsing is needed.

func ParseResponsePaginationFromBody added in v0.5.0

func ParseResponsePaginationFromBody(r io.Reader) (ResponsePagination, []byte, error)

func ParseResponsePaginationFromRaw added in v0.5.0

func ParseResponsePaginationFromRaw(b []byte) (ResponsePagination, error)

type Section

type Section struct {
	ID           uint      `json:"id"`
	SuiteID      uint      `json:"suite_id"`
	Name         string    `json:"name"`
	Description  *string   `json:"description"`
	ParentID     *uint     `json:"parent_id"`
	DisplayOrder uint      `json:"display_order"`
	Depth        uint      `json:"depth"`
	ChildIDs     []uint    `json:"child_ids"` // not in API
	Lineage      Metadatas `json:"lineage"`
}

type SectionAPI added in v0.2.0

type SectionAPI struct {
	// contains filtered or unexported fields
}

func NewSectionAPI added in v0.2.0

func NewSectionAPI(client *Client) SectionAPI

func (SectionAPI) GetSectionSetAll added in v0.4.0

func (api SectionAPI) GetSectionSetAll(ctx context.Context, projectID uint, qry url.Values) (*SectionSet, error)

func (SectionAPI) GetSections added in v0.2.0

func (api SectionAPI) GetSections(ctx context.Context, projectID, limit, offset uint, qry url.Values) (*GetSectionsResponse, *http.Response, error)

type SectionSet

type SectionSet struct {
	Sections map[uint]Section `json:"sections,omitempty"`
}

func NewSectionSet

func NewSectionSet() *SectionSet

func ReadFileSectionSet

func ReadFileSectionSet(filename string) (*SectionSet, error)

func (*SectionSet) Add

func (set *SectionSet) Add(sections ...Section)

func (*SectionSet) BuildLineage added in v0.5.0

func (set *SectionSet) BuildLineage(leafID uint) Metadatas

func (*SectionSet) GetByName

func (set *SectionSet) GetByName(name string, depth int) []Section

func (*SectionSet) GetChildren

func (set *SectionSet) GetChildren(id uint) []Section

func (*SectionSet) GetChildrenIDsFlat

func (set *SectionSet) GetChildrenIDsFlat(id uint, recurse bool) ([]uint, error)

GetChildrenIDsFlat returns a list of sectionIDs in flat sorted order, e.g. not depth first order.

func (*SectionSet) IDs

func (set *SectionSet) IDs() []uint

func (*SectionSet) Inflate

func (set *SectionSet) Inflate() error

func (*SectionSet) Len

func (set *SectionSet) Len() uint

func (*SectionSet) LineageIDsStringToNames added in v0.5.0

func (set *SectionSet) LineageIDsStringToNames(lin, sep string) (string, error)

func (*SectionSet) ReadFileJSON added in v0.3.0

func (set *SectionSet) ReadFileJSON(filename string) error

func (*SectionSet) WriteFileJSON

func (set *SectionSet) WriteFileJSON(filename string, perm os.FileMode, prefix, indent string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL