tms

package module
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README

Test IT TMS Adapter for Golang

Compatibility

Test IT Adapters-Go
5.2.5 v0.3.5
5.3 v0.3.5-tms-5.3
5.4 v0.4.2-tms-5.4
5.5 v0.6.1-tms-5.5
5.6 v0.7.0-tms-5.6
Cloud v0.8.0 +
  1. For current versions, see the releases tab.
  2. Starting with 5.2, we have added a TMS postscript, which means that the utility is compatible with a specific enterprise version.
  3. If you are in doubt about which version to use, check with the support staff. support@yoonion.ru

For other versions compatibility check api-client compatibility - https://github.com/testit-tms/api-client-golang
and previous version of adapter

Getting Started

Installation
go get github.com/testit-tms/adapters-go@<necessary package version>

Usage

Configuration
Description File property Environment variable
Location of the TMS instance url TMS_URL
API secret key How to getting API secret key? privateToken TMS_PRIVATE_TOKEN
ID of project in TMS instance How to getting project ID? projectId TMS_PROJECT_ID
ID of configuration in TMS instance How to getting configuration ID? configurationId TMS_CONFIGURATION_ID
ID of the created test run in TMS instance.
It's necessary for adapterMode 1
testRunId TMS_TEST_RUN_ID
Parameter for specifying the name of test run in TMS instance (It's optional). If it is not provided, it is created automatically testRunName TMS_TEST_RUN_NAME
Adapter mode. Default value - 1. The adapter supports following modes:
1 - in this mode, the adapter sends all results to the test run without filtering or with filtering CLI
2 - in this mode, the adapter creates a new test run and sends results to the new test run
adapterMode TMS_ADAPTER_MODE
It enables/disables certificate validation (It's optional). Default value - true certValidation TMS_CERT_VALIDATION
Mode of automatic creation test cases (It's optional). Default value - false. The adapter supports following modes:
true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)
false - in this mode, the adapter will not create a test case
automaticCreationTestCases TMS_AUTOMATIC_CREATION_TEST_CASES
Mode of automatic updation links to test cases (It's optional). Default value - false. The adapter supports following modes:
true - in this mode, the adapter will update links to test cases
false - in this mode, the adapter will not update link to test cases
automaticUpdationLinksToTestCases TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES
Enable debug logs (It's optional). Default value - false isDebug TMS_IS_DEBUG
File

Create tms.config.json file in the project directory:

{
  "url": "URL",
  "privateToken": "USER_PRIVATE_TOKEN",
  "projectId": "PROJECT_ID",
  "configurationId": "CONFIGURATION_ID",
  "testRunId": "TEST_RUN_ID",
  "testRunName": "TEST_RUN_NAME",
  "automaticCreationTestCases": false,
  "automaticUpdationLinksToTestCases": false,
  "certValidation": true,
  "adapterMode": "1",
  "isDebug": true
}

Alternatively to set TMS_CONFIG_FILE you can place your tms.config.json file

to the folder with _test.go files you are want to work with,

but for multifolder structure TMS_CONFIG_FILE is prefered.

How to run

If you specified TestRunId, then just run the command:

export TMS_CONFIG_FILE=<ABSOLUTE_PATH_TO_CONFIG_FILE>
cd ci_tests
go test

To create and complete TestRun you can use the Test IT CLI:

export TMS_TOKEN=<YOUR_TOKEN>
testit \
  testrun create
  --url https://tms.testit.software \
  --project-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
  --testrun-name "New test run" \
  --output tmp/output.txt

export TMS_TEST_RUN_ID=$(cat output.txt)  

export TMS_CONFIG_FILE=<ABSOLUTE_PATH_TO_CONFIG_FILE>
cd ci_tests
go test

testit testrun complete
  --url https://tms.testit.software \
  --testrun-id $(cat tmp/output.txt)
Run with filter

To create filter by autotests you can use the Test IT CLI (use adapterMode "1" for run with filter):

$ export TMS_TOKEN=<YOUR_TOKEN>
$ testit autotests_filter 
  --url https://tms.testit.software \
  --configuration-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
  --testrun-id 6d4ac4b7-dd67-4805-b879-18da0b89d4a8 \
  --framework golang \
  --output tmp/filter.txt

$ export TMS_TEST_RUN_ID=6d4ac4b7-dd67-4805-b879-18da0b89d4a8
$ export TMS_ADAPTER_MODE=1

$ export TMS_CONFIG_FILE=<ABSOLUTE_PATH_TO_CONFIG_FILE>
$ go test -run "$(cat tmp/filter.txt)"
Asserting usage notes
  • You should use tms.True as asserts for correct TestResult generation, e.g.:
expectedValue := 4
actualValue := 5 // function call you are testing
					
tms.True(t, actualValue == expectedValue) // its be an error and failed test, cause assert with false result.
  • You can use tms.True both in tms.Test and tms.Step functions
Metadata of autotest

Use metadata to specify information about autotest.

Description of metadata:

  • WorkItemIds - a method that links autotests with manual tests. Receives the array of manual tests' IDs
  • DisplayName - internal autotest name (used in Test IT)
  • ExternalId - unique internal autotest ID (used in Test IT)
  • Title - autotest name specified in the autotest card. If not specified, the name from the displayName method is used
  • Description - autotest description specified in the autotest card
  • Labels - labels listed in the autotest card
  • Tags - tags listed in the autotest card
  • Links - links listed in the autotest card ( not in the TestResult card. Additionally, there is URL validation on Link.Url and it's must be a correct URL. )
  • Step - the designation of the step

Description of methods:

  • tms.AddLinks - add links to the autotest TestResult (not the autotest card, for card see TestMetadata.Links. Additionally, there is URL validation on Link.Url and it's must be a correct URL. ).
  • tms.AddAttachments - add attachments to the autotest result.
  • tms.AddAtachmentsFromString - add attachments from string to the autotest result.
  • tms.AddMessage - add message to the autotest result.
Examples

More examples and project there: https://github.com/testit-tms/go-examples

Simple test
package examples

import (
  "testing"

  "github.com/testit-tms/adapters-go"
)


func TestSteps_Success(t *testing.T) {

	// links at the autotest card
	links := []tms.Link{{
		Url:         "http://google.com",
		Title:       "Link title",
		Description: "Link description",
		LinkType:    "Requirement",
	}}

	labels := []string{"Test labels"}
	tags := []string{"Test tags"}
	parameters := map[string]interface{}{
		"param1": "value1",
	}

	tms.Test(t,
		tms.TestMetadata{
			DisplayName: "steps success",
			// Links for autotest card
			Links:      links,
			Labels:     labels,
			Tags:     	tags,
			Parameters: parameters,
			// other properties...
		},
		func() {

			// for TestResult attachment
			// tms.AddAtachments("tms.config.json")

			// add links to TestResult
			tms.AddLinks(tms.Link{
				Url:         "https://testit.software",
				Title:       "Link title",
				Description: "Link description",
				LinkType:    tms.LINKTYPE_RELATED,
			})
			// add message to TestResult
			tms.AddMessage("Test Message")

			// step declaration
			tms.Step(
				tms.StepMetadata{
					Name:        "step 1",
					Description: "step 1 description",
				},
				func() {
					tms.Step(tms.StepMetadata{
						Name:        "step 1.1",
						Description: "step 1.1 description",
					}, func() {
						tms.Step(tms.StepMetadata{}, func() {
							tms.True(t, true)
						})
						tms.True(t, true)
					})
					tms.True(t, true)
				},
			)
			tms.Step(
				tms.StepMetadata{
					Name:        "step 2",
					Description: "step 2 description",
				},
				func() {
					tms.Step(tms.StepMetadata{
						Name:        "step 2.1",
						Description: "step 2.1 description",
					}, func() {
						tms.Step(tms.StepMetadata{}, func() {
							tms.True(t, true)
						})
						tms.True(t, true)
					})
					tms.True(t, true)
				},
			)
		})
}
Parameterized test
package examples

import (
  "testing"

  "github.com/testit-tms/adapters-go"
)

func TestParameters_success(t *testing.T) {
	tests := []struct {
		name           string
		parameters     map[string]interface{}
		stepName       string
		stepParameters map[string]interface{}
		expValue       bool
	}{
		{
			name: "add parameters success",
			parameters: map[string]interface{}{
				"param1": "value1",
				"param2": 15,
			},
			stepName: "step1",
			stepParameters: map[string]interface{}{
				"param1": "value1",
				"param2": 15,
			},
			expValue: true,
		},
		{
			name: "add parameters failed",
			parameters: map[string]interface{}{
				"param1": "value1",
				"param2": 15,
			},
			stepName: "step1",
			stepParameters: map[string]interface{}{
				"param1": "value1",
				"param2": 15,
			},
			expValue: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			tms.Test(t, tms.TestMetadata{
				DisplayName: tt.name,
				Parameters:  tt.parameters,
			}, func() {
				tms.Step(
					tms.StepMetadata{
						Name:       tt.stepName,
						Parameters: tt.stepParameters,
					}, func() {
						tms.True(t, tt.expValue)
					})
			})
		})
	}
}

Contributing

You can help to develop the project. Any contributions are greatly appreciated.

  • If you have suggestions for adding or removing projects, feel free to open an issue to discuss it, or create a direct pull request after you edit the README.md file with necessary changes.
  • Make sure to check your spelling and grammar.
  • Create individual PR for each suggestion.
  • Read the Code Of Conduct before posting your first idea as well.

License

Distributed under the Apache-2.0 License. See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAtachments

func AddAtachments(paths ...string)

func AddAtachmentsFromString

func AddAtachmentsFromString(name, content string)
func AddLinks(l models.Link)

func AddMessage

func AddMessage(m string)

func AfterTest

func AfterTest(t *testing.T, m StepMetadata, f func())

func BeforeTest

func BeforeTest(t *testing.T, m StepMetadata, f func())

func Condition

func Condition(t *testing.T, condition assert.Comparison, msgAndArgs ...interface{})

func Contains

func Contains(t *testing.T, s interface{}, contains interface{}, msgAndArgs ...interface{})

func DirExists

func DirExists(t *testing.T, path string, msgAndArgs ...interface{})

func ElementsMatch

func ElementsMatch(t *testing.T, listA interface{}, listB interface{}, msgAndArgs ...interface{})

func Empty

func Empty(t *testing.T, object interface{}, msgAndArgs ...interface{})

func Equal

func Equal(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func EqualError

func EqualError(t *testing.T, theError error, errString string, msgAndArgs ...interface{})

func EqualValues

func EqualValues(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func Error

func Error(t *testing.T, err error, msgAndArgs ...interface{})

func ErrorAs

func ErrorAs(t *testing.T, err error, target interface{}, msgAndArgs ...interface{})

func ErrorIs

func ErrorIs(t *testing.T, err error, target error, msgAndArgs ...interface{})

func Exactly

func Exactly(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func False

func False(t *testing.T, value bool, msgAndArgs ...interface{})

func Greater

func Greater(t *testing.T, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})

func GreaterOrEqual

func GreaterOrEqual(t *testing.T, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})

func Implements

func Implements(t *testing.T, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})

func InDelta

func InDelta(t *testing.T, expected, actual interface{}, delta float64, msgAndArgs ...interface{})

func IsType

func IsType(t *testing.T, expectedType interface{}, object interface{}, msgAndArgs ...interface{})

func JSONEq

func JSONEq(t *testing.T, expected, actual string, msgAndArgs ...interface{})

func Len

func Len(t *testing.T, object interface{}, length int, msgAndArgs ...interface{})

func Less

func Less(t *testing.T, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})

func LessOrEqual

func LessOrEqual(t *testing.T, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})

func Nil

func Nil(t *testing.T, object interface{}, msgAndArgs ...interface{})

func NoError

func NoError(t *testing.T, err error, msgAndArgs ...interface{})

func NotContains

func NotContains(t *testing.T, s interface{}, contains interface{}, msgAndArgs ...interface{})

func NotEmpty

func NotEmpty(t *testing.T, object interface{}, msgAndArgs ...interface{})

func NotEqual

func NotEqual(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func NotEqualValues

func NotEqualValues(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func NotNil

func NotNil(t *testing.T, object interface{}, msgAndArgs ...interface{})

func NotSame

func NotSame(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func NotSubset

func NotSubset(t *testing.T, list, subset interface{}, msgAndArgs ...interface{})

func NotZero

func NotZero(t *testing.T, i interface{}, msgAndArgs ...interface{})

func Regexp

func Regexp(t *testing.T, rx interface{}, str interface{}, msgAndArgs ...interface{})

func Same

func Same(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{})

func Step

func Step(m StepMetadata, f func())

func Subset

func Subset(t *testing.T, list, subset interface{}, msgAndArgs ...interface{})

func Test

func Test(t *testing.T, m TestMetadata, f func())

func True

func True(t *testing.T, value bool, msgAndArgs ...interface{})

func WithinDuration

func WithinDuration(t *testing.T, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{})

func Zero

func Zero(t *testing.T, i interface{}, msgAndArgs ...interface{})

Types

type Link = models.Link

type LinkType

type LinkType = models.LinkType

type StepMetadata

type StepMetadata struct {
	Name        string
	Description string
	Parameters  map[string]interface{}
}

type StepResult added in v0.8.3

type StepResult struct {
	Name          string
	Description   string
	ChildrenSteps []StepResult
	Status        string
	StartedOn     time.Time
	CompletedOn   time.Time
	Duration      int64
	Attachments   []string
	Parameters    map[string]interface{}
}

type TestMetadata

type TestMetadata struct {
	ClassName   string
	Title       string
	NameSpace   string
	Description string
	DisplayName string
	Parameters  map[string]interface{}
	Links       []models.Link
	Labels      []string
	Tags        []string
	ExternalId  string
	WorkItemIds []string
}

type TestResult added in v0.8.3

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

Directories

Path Synopsis
pkg
tms module

Jump to

Keyboard shortcuts

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