File: crontrigger.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package v2

import (
	"testing"
	"time"

	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/acceptance/tools"
	"github.com/gophercloud/gophercloud/openstack/workflow/v2/crontriggers"
	"github.com/gophercloud/gophercloud/openstack/workflow/v2/workflows"
	th "github.com/gophercloud/gophercloud/testhelper"
)

// CreateCronTrigger creates a cron trigger for the given workflow.
func CreateCronTrigger(t *testing.T, client *gophercloud.ServiceClient, workflow *workflows.Workflow) (*crontriggers.CronTrigger, error) {
	crontriggerName := tools.RandomString("crontrigger_", 5)
	t.Logf("Attempting to create cron trigger: %s", crontriggerName)

	firstExecution := time.Now().AddDate(1, 0, 0)
	createOpts := crontriggers.CreateOpts{
		WorkflowID: workflow.ID,
		Name:       crontriggerName,
		Pattern:    "0 0 1 1 *",
		WorkflowInput: map[string]interface{}{
			"msg": "Hello World!",
		},
		FirstExecutionTime: &firstExecution,
	}
	crontrigger, err := crontriggers.Create(client, createOpts).Extract()
	if err != nil {
		return crontrigger, err
	}
	t.Logf("Cron trigger created: %s", crontriggerName)
	th.AssertEquals(t, crontrigger.Name, crontriggerName)
	return crontrigger, nil
}