Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,21 @@ jobs:
echo "TMS_TEST_RUN_ID=$(<${{ env.TEMP_FILE }})" >> $GITHUB_ENV
- name: Test
run: |
chmod +x ./scripts/get_sync_storage_version.sh
chmod +x ./scripts/get_sync_storage.sh

export SYNC_STORAGE_VERSION=$(./scripts/get_sync_storage_version.sh)

# start sync storage before all other processes
./scripts/get_sync_storage.sh $SYNC_STORAGE_VERSION
nohup .caches/syncstorage-linux-amd64 --testRunId ${{ env.TMS_TEST_RUN_ID }} --port 49152 \
--baseURL ${{ env.TMS_URL }} --privateToken ${{ env.TMS_PRIVATE_TOKEN }} > service.log 2>&1 &
curl -v http://127.0.0.1:49152/health || true

cd ci_tests
go test ./... || exit 0
go test -parallel 4 ./... || true
sleep 1
curl -v http://127.0.0.1:49152/wait-completion?testRunId=${{ env.TMS_TEST_RUN_ID }} || true
- name: Validate
run: |
dotnet test --configuration Debug --no-build --logger:"console;verbosity=detailed" api-validator-dotnet
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
go.work
*tms.config.json
examples
go.sum
go.sum
*/build/.caches
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 66 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ https://github.com/testit-tms/api-client-golang
and previous version of adapter


## What's new in v1.0.0?

- New logic with a fix for test results loading
- Added sync-storage subprocess usage for worker synchronization on port **49152** by defailt.

### How to run v1.0+ locally?

You can change nothing, it's full compatible with previous versions of adapters for local run on all OS.


### How to run v1.0+ with CI/CD?

For CI/CD pipelines, we recommend starting the sync-storage instance before the adapter and waiting for its completion within the same job.

You can see how we implement this [here.](https://github.com/testit-tms/adapters-go/tree/main/.github/workflows/test.yml#82)

- to get the latest version of sync-storage, please use our [script](https://github.com/testit-tms/adapters-go/tree/main/scripts/curl_last_version.sh)

- To download a specific version of sync-storage, use our [script](https://github.com/testit-tms/adapters-go/tree/main/scripts/get_sync_storage.sh) and pass the desired version number as the first parameter. Sync-storage will be downloaded as `.caches/syncstorage-linux-amd64`

1. Create an empty test run using `testit-cli` or use an existing one, and save the `testRunId`.
2. Start **sync-storage** with the correct parameters as a background process (alternatives to nohup can be used). Stream the log output to the `service.log` file:
```bash
nohup .caches/syncstorage-linux-amd64 --testRunId ${{ env.TMS_TEST_RUN_ID }} --port 49152 \
--baseURL ${{ env.TMS_URL }} --privateToken ${{ env.TMS_PRIVATE_TOKEN }} > service.log 2>&1 &
```
3. Start the adapter using adapterMode=1 or adapterMode=0 for the selected testRunId.
4. Wait for sync-storage to complete background jobs by calling:
```bash
curl -v http://127.0.0.1:49152/wait-completion?testRunId=${{ env.TMS_TEST_RUN_ID }} || true
```
5. You can read the sync-storage logs from the service.log file.



## Getting Started

### Installation
Expand All @@ -33,19 +68,21 @@ go get github.com/testit-tms/adapters-go@<necessary package version>

### Configuration

| Description | File property | Environment variable |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|--------------------------------------------|
| Location of the TMS instance | url | TMS_URL |
| API secret key [How to getting API secret key?](https://github.com/testit-tms/.github/tree/main/configuration#privatetoken) | privateToken | TMS_PRIVATE_TOKEN |
| ID of project in TMS instance [How to getting project ID?](https://github.com/testit-tms/.github/tree/main/configuration#projectid) | projectId | TMS_PROJECT_ID |
| ID of configuration in TMS instance [How to getting configuration ID?](https://github.com/testit-tms/.github/tree/main/configuration#configurationid) | configurationId | TMS_CONFIGURATION_ID |
| ID of the created test run in TMS instance. <br/>It's necessary for **adapterMode** 1 | testRunId | TMS_TEST_RUN_ID |
| Description | File property | Environment variable |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|--------------------------------------------|
| Location of the TMS instance | url | TMS_URL |
| API secret key [How to getting API secret key?](https://github.com/testit-tms/.github/tree/main/configuration#privatetoken) | privateToken | TMS_PRIVATE_TOKEN |
| ID of project in TMS instance [How to getting project ID?](https://github.com/testit-tms/.github/tree/main/configuration#projectid) | projectId | TMS_PROJECT_ID |
| ID of configuration in TMS instance [How to getting configuration ID?](https://github.com/testit-tms/.github/tree/main/configuration#configurationid) | configurationId | TMS_CONFIGURATION_ID |
| ID of the created test run in TMS instance. <br/>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:<br>1 - in this mode, the adapter sends all results to the test run without filtering or [with filtering CLI](#run-with-filter)<br/>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:<br/>true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)<br/>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:<br/>true - in this mode, the adapter will update links to test cases<br/>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 |
| Adapter mode. Default value - 1. The adapter supports following modes:<br>1 - in this mode, the adapter sends all results to the test run without filtering or [with filtering CLI](#run-with-filter)<br/>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:<br/>true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)<br/>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:<br/>true - in this mode, the adapter will update links to test cases<br/>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 |
| Sync storage port (**It's optional, 49152 by default**) | syncStoragePort | TMS_SYNC_STORAGE_PORT |
| Mode of import type selection when launching autotests (**It's optional**). Default value - false. The adapter supports following modes:<br/>true - in this mode, the adapter will create/update each autotest in real time<br/>false - in this mode, the adapter will create/update multiple autotests | importRealtime | TMS_IMPORT_REALTIME |

#### File

Expand Down Expand Up @@ -108,6 +145,23 @@ testit testrun complete
--testrun-id $(cat tmp/output.txt)
```

### Run with parallelism

Add t.Parallel() to desired test methods:

```golang
func TestFixture_success(t *testing.T) {
t.Parallel()
...
```

Then run with parallel option:

```bash
go test -parallel 4 ./...
```


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

Expand Down
2 changes: 2 additions & 0 deletions ci_tests/before_after_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func TestFixture_success(t *testing.T) {
t.Parallel()
tms.BeforeTest(t,
tms.StepMetadata{
Name: "before test",
Expand Down Expand Up @@ -55,6 +56,7 @@ func TestFixture_success(t *testing.T) {
}

func TestFixture_failed(t *testing.T) {
t.Parallel()
tms.BeforeTest(t,
tms.StepMetadata{
Name: "before test",
Expand Down
2 changes: 2 additions & 0 deletions ci_tests/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
)

func TestMetadata_without_metadata_success(t *testing.T) {
t.Parallel()
tms.Test(t, tms.TestMetadata{},
func() {
tms.True(t, true)
})
}

func TestMetadata_without_metadata_failed(t *testing.T) {
t.Parallel()
tms.Test(t,
tms.TestMetadata{},
func() {
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Config struct {
AutomaticCreationTestCases bool `json:"automaticCreationTestCases" env:"TMS_AUTOMATIC_CREATION_TEST_CASES" env-default:"false"`
AutomaticUpdationLinksToTestCases bool `json:"automaticUpdationLinksToTestCases" env:"TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES" env-default:"false"`
CertValidation bool `json:"certValidation" env:"TMS_CERT_VALIDATION" env-default:"true"`
SyncStoragePort string `json:"syncStoragePort" env:"TMS_SYNC_STORAGE_PORT" env-default:"49152"`
ImportRealtime bool `json:"importRealtime" env:"TMS_IMPORT_REALTIME" env-default:"false"`
}

func MustLoad() *Config {
Expand Down
35 changes: 30 additions & 5 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (

"github.com/jtolds/gls"
"github.com/testit-tms/adapters-go/config"
"github.com/testit-tms/adapters-go/syncstorage"

"golang.org/x/exp/slog"
)

var (
cfg *config.Config
client *tmsClient
logger *slog.Logger
ctxMgr *gls.ContextManager
testPhaseObjects map[string]*testPhaseContainer
cfg *config.Config
client *tmsClient
logger *slog.Logger
ctxMgr *gls.ContextManager
testPhaseObjects map[string]*testPhaseContainer
syncStorageRunner *syncstorage.Runner
)

const (
Expand All @@ -36,6 +38,29 @@ func init() {
}
ctxMgr = gls.NewContextManager()
testPhaseObjects = make(map[string]*testPhaseContainer)

// Initialize Sync Storage
initSyncStorage()
}

func initSyncStorage() {
testRunID := cfg.TestRunId
if testRunID == "" {
return
}

syncStorageRunner = syncstorage.NewRunner(
testRunID,
cfg.SyncStoragePort,
cfg.Url,
cfg.Token,
logger,
)

if !syncStorageRunner.Start() {
logger.Warn("Failed to start Sync Storage, continuing without it")
syncStorageRunner = nil
}
}

func callCreateTestRun(client *tmsClient, cfg *config.Config) {
Expand Down
1 change: 1 addition & 0 deletions scripts/curl_last_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -s "https://api.github.com/repos/testit-tms/sync-storage-public/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
7 changes: 7 additions & 0 deletions scripts/get_sync_storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SYNC_STORAGE_VERSION=$1

mkdir -p .caches

wget -O .caches/syncstorage-linux-amd64 \
"https://github.com/testit-tms/sync-storage-public/releases/download/${SYNC_STORAGE_VERSION}/syncstorage-${SYNC_STORAGE_VERSION}-linux_amd64"
chmod +x .caches/syncstorage-linux-amd64
1 change: 1 addition & 0 deletions scripts/get_sync_storage_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grep 'syncStorageVersion\s*=' syncstorage/runner.go | sed 's/.*= "\([^"]*\)".*/\1/'
Loading
Loading