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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package testing
import (
"fmt"
"net/http"
"reflect"
"testing"
"time"
"github.com/gophercloud/gophercloud/openstack/workflow/v2/crontriggers"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
func TestCreateCronTrigger(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/cron_triggers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusCreated)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
{
"created_at": "1970-01-01 00:00:00",
"id": "1",
"name": "trigger",
"pattern": "* * * * *",
"project_id": "p1",
"remaining_executions": 42,
"scope": "private",
"updated_at": "1970-01-01 00:00:00",
"first_execution_time": "1970-01-01 00:00:00",
"next_execution_time": "1970-01-01 00:00:00",
"workflow_id": "w1",
"workflow_input": "{\"msg\": \"hello\"}",
"workflow_name": "my_wf",
"workflow_params": "{\"msg\": \"world\"}"
}
`)
})
firstExecution := time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
opts := &crontriggers.CreateOpts{
WorkflowID: "w1",
Name: "trigger",
FirstExecutionTime: &firstExecution,
WorkflowParams: map[string]interface{}{
"msg": "world",
},
WorkflowInput: map[string]interface{}{
"msg": "hello",
},
}
actual, err := crontriggers.Create(fake.ServiceClient(), opts).Extract()
if err != nil {
t.Fatalf("Unable to create cron trigger: %v", err)
}
expected := &crontriggers.CronTrigger{
ID: "1",
Name: "trigger",
Pattern: "* * * * *",
ProjectID: "p1",
RemainingExecutions: 42,
Scope: "private",
WorkflowID: "w1",
WorkflowName: "my_wf",
WorkflowParams: map[string]interface{}{
"msg": "world",
},
WorkflowInput: map[string]interface{}{
"msg": "hello",
},
CreatedAt: time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC),
FirstExecutionTime: &firstExecution,
NextExecutionTime: &firstExecution,
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Expected %#v, but was %#v", expected, actual)
}
}
|