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`.
178 lines
5.2 KiB
Go
178 lines
5.2 KiB
Go
package session
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/server/common/config"
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin"
|
|
"go.temporal.io/server/common/resolver"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type (
|
|
sessionTestSuite struct {
|
|
suite.Suite
|
|
controller *gomock.Controller
|
|
}
|
|
)
|
|
|
|
func TestSessionTestSuite(t *testing.T) {
|
|
s := new(sessionTestSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *sessionTestSuite) SetupSuite() {
|
|
|
|
}
|
|
|
|
func (s *sessionTestSuite) TearDownSuite() {
|
|
|
|
}
|
|
|
|
func (s *sessionTestSuite) SetupTest() {
|
|
s.controller = gomock.NewController(s.T())
|
|
}
|
|
|
|
func (s *sessionTestSuite) TearDownTest() {
|
|
s.controller.Finish()
|
|
}
|
|
|
|
func (s *sessionTestSuite) TestBuildDSN() {
|
|
testCases := []struct {
|
|
name string
|
|
in config.SQL
|
|
outURLPath string
|
|
outIsolationKey string
|
|
outIsolationVal string
|
|
expectInvalidConfig bool
|
|
}{
|
|
{
|
|
name: "no connect attributes",
|
|
in: config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
},
|
|
outIsolationKey: "transaction_isolation",
|
|
outIsolationVal: "'READ-COMMITTED'",
|
|
outURLPath: "test:pass@tcp(192.168.0.1:3306)/db1?",
|
|
},
|
|
{
|
|
name: "with connect attributes",
|
|
in: config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
ConnectAttributes: map[string]string{"k1": "v1", "k2": "v2"},
|
|
},
|
|
outIsolationKey: "transaction_isolation",
|
|
outIsolationVal: "'READ-COMMITTED'",
|
|
outURLPath: "test:pass@tcp(192.168.0.1:3306)/db1?",
|
|
},
|
|
{
|
|
name: "override isolation level (quoted, shorthand)",
|
|
in: config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
ConnectAttributes: map[string]string{"k1": "v1", "k2": "v2", "tx_isolation": "'REPEATABLE-READ'"},
|
|
},
|
|
outIsolationKey: "tx_isolation",
|
|
outIsolationVal: "'repeatable-read'",
|
|
outURLPath: "test:pass@tcp(192.168.0.1:3306)/db1?",
|
|
},
|
|
{
|
|
name: "override isolation level (unquoted, shorthand)",
|
|
in: config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
ConnectAttributes: map[string]string{"k1": "v1", "k2": "v2", "tx_isolation": "REPEATABLE-READ"},
|
|
},
|
|
outIsolationKey: "tx_isolation",
|
|
outIsolationVal: "'repeatable-read'",
|
|
outURLPath: "test:pass@tcp(192.168.0.1:3306)/db1?",
|
|
},
|
|
{
|
|
name: "override isolation level (unquoted, full name)",
|
|
in: config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
ConnectAttributes: map[string]string{"k1": "v1", "k2": "v2", "transaction_isolation": "REPEATABLE-READ"},
|
|
},
|
|
outIsolationKey: "transaction_isolation",
|
|
outIsolationVal: "'repeatable-read'",
|
|
outURLPath: "test:pass@tcp(192.168.0.1:3306)/db1?",
|
|
},
|
|
}
|
|
|
|
for _, dbKind := range []sqlplugin.DbKind{sqlplugin.DbKindMain, sqlplugin.DbKindVisibility} {
|
|
for _, tc := range testCases {
|
|
s.Run(fmt.Sprintf("%s: %s", dbKind.String(), tc.name), func() {
|
|
r := resolver.NewMockServiceResolver(s.controller)
|
|
r.EXPECT().Resolve(tc.in.ConnectAddr).Return([]string{tc.in.ConnectAddr})
|
|
|
|
out, err := buildDSN(dbKind, &tc.in, r)
|
|
if tc.expectInvalidConfig {
|
|
s.Error(err, "Expected an invalid configuration error")
|
|
} else {
|
|
s.NoError(err)
|
|
}
|
|
s.True(strings.HasPrefix(out, tc.outURLPath), "invalid url path")
|
|
tokens := strings.Split(out, "?")
|
|
s.Equal(2, len(tokens), "invalid url")
|
|
qry, err := url.Parse("?" + tokens[1])
|
|
s.NoError(err)
|
|
wantAttrs := buildExpectedURLParams(dbKind, tc.in.ConnectAttributes, tc.outIsolationKey, tc.outIsolationVal)
|
|
s.Equal(wantAttrs, qry.Query(), "invalid dsn url params")
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *sessionTestSuite) Test_Visibility_DoesntSupport_interpolateParams() {
|
|
cfg := config.SQL{
|
|
User: "test",
|
|
Password: "pass",
|
|
ConnectProtocol: "tcp",
|
|
ConnectAddr: "192.168.0.1:3306",
|
|
DatabaseName: "db1",
|
|
ConnectAttributes: map[string]string{"interpolateParams": "ignored"},
|
|
}
|
|
r := resolver.NewMockServiceResolver(s.controller)
|
|
r.EXPECT().Resolve(cfg.ConnectAddr).Return([]string{cfg.ConnectAddr})
|
|
_, err := buildDSN(sqlplugin.DbKindVisibility, &cfg, r)
|
|
s.Error(err, "We should return an error when a MySQL Visibility database is configured with interpolateParams")
|
|
}
|
|
|
|
func buildExpectedURLParams(dbKind sqlplugin.DbKind, attrs map[string]string, isolationKey string, isolationValue string) url.Values {
|
|
result := make(map[string][]string, len(dsnAttrOverrides)+len(attrs)+1)
|
|
for k, v := range attrs {
|
|
result[k] = []string{v}
|
|
}
|
|
result[isolationKey] = []string{isolationValue}
|
|
for k, v := range dsnAttrOverrides {
|
|
result[k] = []string{v}
|
|
}
|
|
result["rejectReadOnly"] = []string{"true"}
|
|
if dbKind != sqlplugin.DbKindVisibility {
|
|
result["interpolateParams"] = []string{"true"}
|
|
}
|
|
return result
|
|
}
|