gorp

package
v5.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	LogLevelDebug = "DEBUG"
	LogLevelInfo  = "INFO"
	LogLevelError = "ERROR"
)

Client constants

Variables

View Source
var LaunchModes = launchModeValuesType{
	Default: "DEFAULT",
	Debug:   "DEBUG",
}

LaunchModes is enum values for easy access

View Source
var MergeTypes = mergeTypeValuesType{
	Deep:  "DEEP",
	Basic: "BASIC",
}

MergeTypes is enum values for easy access

View Source
var Statuses = statusValuesType{
	Passed:      "PASSED",
	Failed:      "FAILED",
	Stopped:     "STOPPED",
	Skipped:     "SKIPPED",
	Interrupted: "INTERRUPTED",
	Canceled:    "CANCELLED",
	Info:        "INFO",
	Warn:        "WARN",
}

Statuses is enum values for easy access

View Source
var TestItemTypes = testItemTypeValuesType{
	Suite:        "SUITE",
	Story:        "STORY",
	Test:         "TEST",
	Scenario:     "SCENARIO",
	Step:         "STEP",
	BeforeClass:  "BEFORE_CLASS",
	BeforeGroups: "BEFORE_GROUPS",
	BeforeMethod: "BEFORE_METHOD",
	BeforeSuite:  "BEFORE_SUITE",
	BeforeTest:   "BEFORE_TEST",
	AfterClass:   "AFTER_CLASS",
	AfterGroups:  "AFTER_GROUPS",
	AfterMethod:  "AFTER_METHOD",
	AfterSuite:   "AFTER_SUITE",
	AfterTest:    "AFTER_TEST",
}

TestItemTypes is enum values for easy access

Functions

func ConvertToFilterParams

func ConvertToFilterParams(filter *FilterResource) map[string]string

ConvertToFilterParams converts RP internal filter representation to query string

Types

type Attachment added in v5.0.6

type Attachment struct {
	Name string `json:"name,omitempty"`
}

Attachment represents file attachment in log entries

type Attribute

type Attribute struct {
	Parameter
	System bool `json:"system,omitempty"`
}

Attribute represents ReportPortal's attribute

type Client

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

Client is ReportPortal REST API Client

Example
package main

import (
	"log"
	"os"
	"time"

	"github.com/google/uuid"
)

func main() {
	client := NewClient("", "", "")

	launchUUID := uuid.New()
	launch, err := client.StartLaunch(&StartLaunchRQ{
		Mode: LaunchModes.Default,
		StartRQ: StartRQ{
			Name:        "gorp-test",
			UUID:        &launchUUID,
			StartTime:   NewTimestamp(time.Now()),
			Description: "Demo Launch",
		},
	})
	checkErr(err, "unable to start launch")

	testUUID := uuid.New()
	_, err = client.StartTest(&StartTestRQ{
		LaunchID: launch.ID,
		CodeRef:  "example_test.go",
		UniqueID: "another one unique ID",
		Retry:    false,
		Type:     TestItemTypes.Test,
		StartRQ: StartRQ{
			Name:      "Gorp Test",
			StartTime: Timestamp{time.Now()},
			UUID:      &testUUID,
		},
	})
	checkErr(err, "unable to start test")

	_, err = client.SaveLog(&SaveLogRQ{
		LaunchUUID: launchUUID.String(),
		ItemID:     testUUID.String(),
		Level:      LogLevelInfo,
		LogTime:    Timestamp{time.Now()},
		Message:    "Log without binary",
	})
	checkErr(err, "unable to save log")

	file1, err := os.Open("../../go.mod")
	checkErr(err, "unable to read file")
	file2, err := os.Open("../../go.sum")
	checkErr(err, "unable to read file")

	_, err = client.SaveLogMultipart([]*SaveLogRQ{
		{
			LaunchUUID: launchUUID.String(),
			ItemID:     testUUID.String(),
			Level:      LogLevelInfo,
			Message:    "Log with binary one",
			Attachment: Attachment{
				Name: "go.mod",
			},
		},
		{
			LaunchUUID: launchUUID.String(),
			ItemID:     testUUID.String(),
			Level:      LogLevelInfo,
			Message:    "Log with binary two",
			Attachment: Attachment{
				Name: "go.sum",
			},
		},
	}, []Multipart{
		&FileMultipart{File: file1},
		&ReaderMultipart{ContentType: "text/plain", FileName: file2.Name(), Reader: file2},
	})

	checkErr(err, "unable to save log multipart")

	_, err = client.FinishTest(testUUID.String(), &FinishTestRQ{
		LaunchUUID: launchUUID.String(),
		FinishExecutionRQ: FinishExecutionRQ{
			EndTime: Timestamp{time.Now()},
			Status:  Statuses.Passed,
		},
	})
	checkErr(err, "unable to finish test")

	_, err = client.FinishLaunch(launchUUID.String(), &FinishExecutionRQ{
		Status:  Statuses.Passed,
		EndTime: Timestamp{time.Now()},
	})
	checkErr(err, "unable to finish launch")
}

func checkErr(err error, msg string) {
	if err != nil {
		log.Fatal(msg, err)
	}
}
Output:

func NewClient

func NewClient(host, project, apiKey string) *Client

NewClient creates new instance of Client host - server hostname project - name of the project apiKey - User Token (see user profile page)

func (*Client) FinishLaunch

func (c *Client) FinishLaunch(id string, launch *FinishExecutionRQ) (*FinishLaunchRS, error)

FinishLaunch finishes launch in RP

func (*Client) FinishLaunchRaw

func (c *Client) FinishLaunchRaw(id string, body json.RawMessage) (*FinishLaunchRS, error)

FinishLaunchRaw finishes launch in RP with body in form of bytes buffer

func (*Client) FinishTest

func (c *Client) FinishTest(id string, rq *FinishTestRQ) (*MsgRS, error)

FinishTest finishes test in RP

func (*Client) FinishTestRaw

func (c *Client) FinishTestRaw(id string, body json.RawMessage) (*MsgRS, error)

FinishTestRaw finishes test in RP accepting body as array of bytes

func (*Client) GetFiltersByName

func (c *Client) GetFiltersByName(name string) (*FilterPage, error)

GetFiltersByName retrieves filter by its name

func (*Client) GetLaunches

func (c *Client) GetLaunches() (*LaunchPage, error)

GetLaunches retrieves latest launches

func (*Client) GetLaunchesByFilter

func (c *Client) GetLaunchesByFilter(filter map[string]string) (*LaunchPage, error)

GetLaunchesByFilter retrieves launches by filter

func (*Client) GetLaunchesByFilterName

func (c *Client) GetLaunchesByFilterName(name string) (*LaunchPage, error)

GetLaunchesByFilterName retrieves launches by filter name

func (*Client) GetLaunchesByFilterString

func (c *Client) GetLaunchesByFilterString(filter string) (*LaunchPage, error)

GetLaunchesByFilterString retrieves launches by filter as string

func (*Client) MergeLaunches

func (c *Client) MergeLaunches(rq *MergeLaunchesRQ) (*LaunchResource, error)

MergeLaunches merge two launches

func (*Client) SaveLog

func (c *Client) SaveLog(log *SaveLogRQ) (*EntryCreatedRS, error)

SaveLog attaches log in RP

func (*Client) SaveLogMultipart

func (c *Client) SaveLogMultipart(log []*SaveLogRQ, files []Multipart) (*EntryCreatedRS, error)

SaveLogMultipart saves a batch of logs in RP, along with any associated files (if any).

Example usage:

f, _ := os.Open("someFile.txt")

logs := []*SaveLogRQ{{
	    File: FileAttachment{
	        // note that this value must present in 'files' map as key (see below)
	        Name: "fileAttachment.txt",
	    },
	    LaunchUUID: launchID,
	    ItemID:     itemID,
	    Level:      gorp.LogLevelError,
	    LogTime:    NewTimestamp(time.Now()),
	    Message:    "Important message!",
		}}

files := map[string]*os.File{
			"fileAttachment.txt": f, // key must match the FileAttachment.Name field
		}

resp, err := client.SaveLogMultipart(log, files)

func (*Client) SaveLogs

func (c *Client) SaveLogs(logs ...*SaveLogRQ) (*EntryCreatedRS, error)

SaveLogs saves logs as batch request

func (*Client) StartChildTest

func (c *Client) StartChildTest(parent string, item *StartTestRQ) (*EntryCreatedRS, error)

StartChildTest starts new test in RP

func (*Client) StartChildTestRaw

func (c *Client) StartChildTestRaw(parent string, body json.RawMessage) (*EntryCreatedRS, error)

StartChildTestRaw starts new test in RP accepting request body as array of bytes

func (*Client) StartLaunch

func (c *Client) StartLaunch(launch *StartLaunchRQ) (*EntryCreatedRS, error)

StartLaunch starts new launch in RP

func (*Client) StartLaunchRaw

func (c *Client) StartLaunchRaw(body json.RawMessage) (*EntryCreatedRS, error)

StartLaunchRaw starts new launch in RP with body in form of bytes buffer

func (*Client) StartTest

func (c *Client) StartTest(item *StartTestRQ) (*EntryCreatedRS, error)

StartTest starts new test in RP

func (*Client) StartTestRaw

func (c *Client) StartTestRaw(body json.RawMessage) (*EntryCreatedRS, error)

StartTestRaw starts new test in RP accepting request body as array of bytes

func (*Client) StopLaunch

func (c *Client) StopLaunch(id string) (*MsgRS, error)

StopLaunch forces finishing launch

type EntryCreatedRS

type EntryCreatedRS struct {
	ID string `json:"id,omitempty"`
}

EntryCreatedRS payload

type FileMultipart added in v5.0.6

type FileMultipart struct {
	*os.File
}

FileMultipart is a multipart content in form of file

func (*FileMultipart) Load added in v5.0.6

func (fm *FileMultipart) Load() (fileName, contentType string, reader io.Reader, err error)

type FilterEntity

type FilterEntity struct {
	Field     string `json:"filtering_field"`
	Condition string `json:"condition"`
	Value     string `json:"value"`
}

FilterEntity - One piece of filter

type FilterOrder

type FilterOrder struct {
	SortingColumn string `json:"sorting_column"`
	Asc           bool   `json:"is_asc"`
}

FilterOrder - Describes ordering

type FilterPage

type FilterPage struct {
	Content []*FilterResource
	Response
}

FilterPage - GET Filter response model

type FilterResource

type FilterResource struct {
	ID              string                `json:"id"`
	Name            string                `json:"name"`
	Type            TestItemType          `json:"type"`
	Owner           string                `json:"owner"`
	Entities        []*FilterEntity       `json:"entities"`
	SelectionParams *FilterSelectionParam `json:"selection_parameters,omitempty"`
}

FilterResource - GET Filter response model

type FilterSelectionParam

type FilterSelectionParam struct {
	PageNumber int            `json:"page_number"`
	Orders     []*FilterOrder `json:"orders,omitempty"`
}

FilterSelectionParam - Describes filter ordering

type FinishExecutionRQ

type FinishExecutionRQ struct {
	EndTime     Timestamp    `json:"end_time,omitempty"`
	Status      Status       `json:"status,omitempty"`
	Description string       `json:"description,omitempty"`
	Attributes  []*Attribute `json:"attribute,omitempty"`
}

FinishExecutionRQ payload representation

type FinishLaunchRS

type FinishLaunchRS struct {
	EntryCreatedRS
	Number int64 `json:"number,omitempty"`
}

FinishLaunchRS is finish execution payload

type FinishTestRQ

type FinishTestRQ struct {
	FinishExecutionRQ
	LaunchUUID string `json:"launchUuid,omitempty"`
	TestCaseID string `json:"testCaseId,omitempty"`
	Retry      bool   `json:"retry,omitempty"`
	RetryOf    string `json:"retryOf,omitempty"`
}

FinishTestRQ payload representation

type LaunchMode

type LaunchMode string

LaunchMode - DEFAULT/DEBUG

type LaunchPage

type LaunchPage struct {
	Content []*LaunchResource
	Response
}

LaunchPage - GET Launch response model

type LaunchResource

type LaunchResource struct {
	ID                  int          `json:"id"`
	UUID                string       `json:"uuid"`
	Name                string       `json:"name,omitempty"`
	Number              int          `json:"number"`
	Description         string       `json:"description,omitempty"`
	StartTime           Timestamp    `json:"startTime,omitempty"`
	EndTime             Timestamp    `json:"endTime,omitempty"`
	Status              Status       `json:"status,omitempty"`
	Attributes          []*Attribute `json:"attributes,omitempty"`
	Mode                LaunchMode   `json:"mode,omitempty"`
	ApproximateDuration float32      `json:"approximateDuration,omitempty"`
	HasRetries          bool         `json:"hasRetries,omitempty"`
	Statistics          *Statistics  `json:"statistics,omitempty"`
	Analyzers           []string     `json:"analysing,omitempty"` //nolint:misspell // defined as described on server end
}

LaunchResource - GET Launch response model

type MergeLaunchesRQ

type MergeLaunchesRQ struct {
	Description             string     `json:"description,omitempty"`
	StartTime               *Timestamp `json:"startTime,omitempty"`
	EndTime                 *Timestamp `json:"endTime,omitempty"`
	ExtendSuitesDescription bool       `json:"extendSuitesDescription,omitempty"`
	Launches                []int      `json:"launches"`
	MergeType               MergeType  `json:"mergeType,omitempty"`
	Mode                    string     `json:"mode,omitempty"`
	Tags                    []string   `json:"tags,omitempty"`
	Name                    string     `json:"name,omitempty"`
}

MergeLaunchesRQ payload representation

type MergeType

type MergeType string

MergeType is type of merge: BASIC or DEEP

type MsgRS

type MsgRS struct {
	Msg string `json:"msg,omitempty"`
}

MsgRS successful operation response payload

type Multipart added in v5.0.6

type Multipart interface {
	// Load loads multipart data
	Load() (fileName, contentType string, reader io.Reader, err error)
}

Multipart is an interface that allows to pass over different types of multipart data sources

type Parameter

type Parameter struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

Parameter represents key-value pair

type ReaderMultipart added in v5.0.6

type ReaderMultipart struct {
	FileName, ContentType string
	io.Reader
}

ReaderMultipart is a multipart content in form of io.Reader

func (*ReaderMultipart) Load added in v5.0.6

func (fm *ReaderMultipart) Load() (fileName, contentType string, reader io.Reader, err error)

type Response

type Response struct {
	// Page is a slice of data returned by server
	Page struct {
		Number        int `json:"number,omitempty"`
		Size          int `json:"size,omitempty"`
		TotalElements int `json:"totalElements,omitempty"`
		TotalPages    int `json:"totalPages,omitempty"`
	} `json:"page,omitempty"`
}

Response is a representation of server response

type SaveLogRQ

type SaveLogRQ struct {
	LaunchUUID string     `json:"launchUuid,omitempty"`
	ItemID     string     `json:"itemUuid,omitempty"`
	LogTime    Timestamp  `json:"time,omitempty"`
	Message    string     `json:"message,omitempty"`
	Level      string     `json:"level,omitempty"`
	Attachment Attachment `json:"file,omitempty"`
}

SaveLogRQ payload representation.

type StartLaunchRQ

type StartLaunchRQ struct {
	StartRQ
	Mode    LaunchMode `json:"mode"`
	Rerun   bool       `json:"rerun,omitempty"`
	RerunOf *uuid.UUID `json:"rerunOf,omitempty"`
}

StartLaunchRQ payload representation

type StartLaunchRS

type StartLaunchRS struct {
	ID string `json:"id,omitempty"`
}

StartLaunchRS payload

type StartRQ

type StartRQ struct {
	UUID        *uuid.UUID   `json:"uuid,omitempty"`
	Name        string       `json:"name,omitempty"`
	Description string       `json:"description,omitempty"`
	Attributes  []*Attribute `json:"attributes,omitempty"`
	StartTime   Timestamp    `json:"start_time,omitempty"`
}

StartRQ payload representation

type StartTestRQ

type StartTestRQ struct {
	StartRQ
	CodeRef    string       `json:"codeRef,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
	UniqueID   string       `json:"uniqueId,omitempty"`
	TestCaseID string       `json:"testCaseId,omitempty"`
	LaunchID   string       `json:"launchUuid,omitempty"`
	Type       TestItemType `json:"type,omitempty"`
	Retry      bool         `json:"retry,omitempty"`
	HasStats   bool         `json:"hasStats,omitempty"`
}

StartTestRQ payload representation

type Statistics

type Statistics struct {
	Executions map[string]int            `json:"executions,omitempty"`
	Defects    map[string]map[string]int `json:"defects,omitempty"`
}

Statistics is a execution stat details

type Status

type Status string

Status represents test item status

type TestItemType

type TestItemType string

TestItemType represents ENUM of test item types

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp is a wrapper around Time to support Epoch milliseconds

func NewTimestamp

func NewTimestamp(t time.Time) Timestamp

NewTimestamp creates Timestamp wrapper for time.Time

func (*Timestamp) MarshalJSON

func (rt *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON converts Epoch milliseconds (timestamp) to appropriate object

func (*Timestamp) UnmarshalJSON

func (rt *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON converts Epoch milliseconds (timestamp) to appropriate object

Jump to

Keyboard shortcuts

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