Skip to content

cito-oss/tempo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tempo

go.dev Go Report Card codecov

Tempo is a Go library for running Go-like tests in a distributed manner using Temporal.

Usage

Add the dependency to your go.mod file:

go get github.com/cito-oss/tempo

Tip

For more examples, check the _example directory.

Then create your first test app:

package main

import (
	"context"

	"github.com/cito-oss/tempo"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"go.temporal.io/sdk/client"
	"go.temporal.io/sdk/worker"
)

func Greeter(ctx context.Context, name string) (string, error) {
	if name == "" {
		name = "World"
	}

	return "Hello " + name, nil
}

func SayHello(t *tempo.T, name string) {
	// use t.Go for workflow.Go
	// use t.WaitGroup for workflow.NewWaitGroup
	// use t.BufferedChannel for workflow.NewBufferedChannel

	t.Run("must greet :name", func(t *tempo.T) {
		var greetings string

		err := t.Task(Greeter, name, &greetings)
		require.NoError(t, err)

		assert.Equal(t, "Hello "+name, greetings)
	})

	t.Run("must greet John Doe", func(t *tempo.T) {
		var greetings string

		err := t.Task(Greeter, "John Doe", &greetings)
		require.NoError(t, err)

		assert.Equal(t, "Hello John Doe", greetings)
	})

	t.Run("must greet World", func(t *tempo.T) {
		var greetings string

		err := t.Task(Greeter, "World", &greetings)
		require.NoError(t, err)

		assert.Equal(t, "Hello World", greetings)
	})
}

func main() {
	cli, err := client.Dial(client.Options{})
	if err != nil {
		panic(err)
	}
	defer cli.Close()

	queue := "default"

	// WORKER
	myworker := worker.New(cli, queue, worker.Options{})

	tempo.Worker(myworker, tempo.Registry{
		Tests: []tempo.Test{
			tempo.NewTestWithInput(SayHello),
		},
		Tasks: []tempo.Task{
			Greeter,
		},
	})

	// non-blocking call
	err = myworker.Start()
	if err != nil {
		panic(err)
	}
	defer myworker.Stop()
	// /WORKER

	// RUNNER
	myrunner := tempo.NewRunner(cli, queue,
		tempo.NewPlan(SayHello, "Tempo"),
	)

	myrunner.SetReporting(true) // enable Allure reporting
	myrunner.SetLimit(1)        // limit number of concurrent tests

	// blocking call
	err = myrunner.Run("v1.0.0")
	if err != nil {
		panic(err)
	}
	// /RUNNER
}

Now run it and check your Temporal:

Temporal Screenshot

Reporting

If you are using the runner, enabled it with:

	myrunner.SetReporting(true)

or if you are invoking tests manually:

	opts := []tempo.Option{
		tempo.WithReporting(true),
	}

	err := tempo.Run(cli, queue, id, plan, nil, opts...)

Then, run your tests. Once they are completed, you will notice that an allure-results folder has been created. You can now generate and view the report using the following commands:

allure generate allure-results --clean -o allure-report
allure open allure-report

Allure Report Screenshot 1 Allure Report Screenshot 2

Important

Please note that reporting is handled by the runner. So, if you have separate applications for the runner and worker, the allure-results folder will be created where the runner is being executed.

Roadmap

  • Reporting
  • Slack integration
  • Support to Temporal Signals
  • Ability to Skip test cases

About

Run distributed Go-like tests using Temporal

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •