mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
113 lines
3.4 KiB
Go
113 lines
3.4 KiB
Go
package routing_test
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/stretchr/testify/assert"
|
|
"go.temporal.io/server/common/routing"
|
|
)
|
|
|
|
type QualifiedWorkflow struct {
|
|
Namespace string
|
|
WorkflowID string
|
|
}
|
|
|
|
func newWorkflowRoute() routing.Route[QualifiedWorkflow] {
|
|
return routing.NewBuilder[QualifiedWorkflow]().
|
|
Constant("api", "v1", "namespaces").
|
|
StringVariable("namespace", func(params *QualifiedWorkflow) *string { return ¶ms.Namespace }).
|
|
Constant("workflows").
|
|
StringVariable("workflowID", func(params *QualifiedWorkflow) *string { return ¶ms.WorkflowID }).
|
|
Build()
|
|
}
|
|
|
|
func ExampleRoute() {
|
|
route := routing.NewBuilder[QualifiedWorkflow]().
|
|
Constant("api", "v1", "namespaces").
|
|
StringVariable("namespace", func(params *QualifiedWorkflow) *string { return ¶ms.Namespace }).
|
|
Constant("workflows").
|
|
StringVariable("workflowID", func(params *QualifiedWorkflow) *string { return ¶ms.WorkflowID }).
|
|
Build()
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/"+route.Representation(), func(w http.ResponseWriter, r *http.Request) {
|
|
params := route.Deserialize(mux.Vars(r))
|
|
_, _ = fmt.Fprintf(w, "Namespace: %s, WorkflowID: %s\n", params.Namespace, params.WorkflowID)
|
|
})
|
|
recorder := httptest.NewRecorder()
|
|
u := "http://localhost/" + route.Path(QualifiedWorkflow{
|
|
Namespace: "TEST-NAMESPACE",
|
|
WorkflowID: "TEST-WORKFLOW-ID",
|
|
})
|
|
router.ServeHTTP(recorder, httptest.NewRequest("GET", u, nil))
|
|
fmt.Println(recorder.Code)
|
|
fmt.Println(recorder.Body.String())
|
|
// Output:
|
|
// 200
|
|
// Namespace: TEST-NAMESPACE, WorkflowID: TEST-WORKFLOW-ID
|
|
}
|
|
|
|
func ExampleRoute_Representation() {
|
|
route := newWorkflowRoute()
|
|
fmt.Println(route.Representation())
|
|
// Output: api/v1/namespaces/{namespace}/workflows/{workflowID}
|
|
}
|
|
|
|
func ExampleRoute_Path() {
|
|
route := newWorkflowRoute()
|
|
params := QualifiedWorkflow{Namespace: "TEST-NAMESPACE", WorkflowID: "TEST-WORKFLOW-ID"}
|
|
fmt.Println(route.Path(params))
|
|
// Output: api/v1/namespaces/TEST-NAMESPACE/workflows/TEST-WORKFLOW-ID
|
|
}
|
|
|
|
func ExampleRoute_Deserialize() {
|
|
route := newWorkflowRoute()
|
|
// Would usually be mux.Vars(r) in a real application
|
|
vars := map[string]string{
|
|
"namespace": "TEST-NAMESPACE",
|
|
"workflowID": "TEST-WORKFLOW-ID",
|
|
}
|
|
params := route.Deserialize(vars)
|
|
fmt.Println(params.Namespace)
|
|
fmt.Println(params.WorkflowID)
|
|
// Output:
|
|
// TEST-NAMESPACE
|
|
// TEST-WORKFLOW-ID
|
|
}
|
|
|
|
func ExampleConstant() {
|
|
fmt.Println(routing.Constant[QualifiedWorkflow]("api", "v1", "namespaces").Representation())
|
|
// Output: api/v1/namespaces
|
|
}
|
|
|
|
func ExampleStringVariable() {
|
|
fmt.Println(routing.StringVariable("namespace", func(params *QualifiedWorkflow) *string { return ¶ms.Namespace }).Representation())
|
|
// Output: {namespace}
|
|
}
|
|
|
|
func TestNewRoute(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
route := newWorkflowRoute()
|
|
|
|
t.Run("Path", func(t *testing.T) {
|
|
assert.Equal(t, "api/v1/namespaces/{namespace}/workflows/{workflowID}", route.Representation())
|
|
})
|
|
|
|
t.Run("Get", func(t *testing.T) {
|
|
params := QualifiedWorkflow{Namespace: "TEST-NAMESPACE", WorkflowID: "TEST-WORKFLOW-ID"}
|
|
assert.Equal(t, "api/v1/namespaces/TEST-NAMESPACE/workflows/TEST-WORKFLOW-ID", route.Path(params))
|
|
})
|
|
|
|
t.Run("Set", func(t *testing.T) {
|
|
params := route.Deserialize(map[string]string{
|
|
"namespace": "TEST-NAMESPACE",
|
|
"workflowID": "TEST-WORKFLOW-ID",
|
|
})
|
|
assert.Equal(t, QualifiedWorkflow{Namespace: "TEST-NAMESPACE", WorkflowID: "TEST-WORKFLOW-ID"}, params)
|
|
})
|
|
}
|