• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 018e1aca-4829-4e25-951b-23cb08010d99

07 Mar 2024 09:20PM UTC coverage: 63.21% (-0.7%) from 63.932%
018e1aca-4829-4e25-951b-23cb08010d99

push

buildkite

web-flow
Add unit tests for common/persistence/sql/factory.go (#5751)

92665 of 146599 relevant lines covered (63.21%)

2349.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.39
/common/persistence/sql/plugin.go
1
// Copyright (c) 2017 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package sql
22

23
import (
24
        "fmt"
25
        "sort"
26

27
        "github.com/uber/cadence/common/config"
28
        "github.com/uber/cadence/common/persistence/sql/sqlplugin"
29
)
30

31
var supportedPlugins = map[string]sqlplugin.Plugin{}
32

33
// RegisterPlugin will register a SQL plugin
34
func RegisterPlugin(pluginName string, plugin sqlplugin.Plugin) {
9✔
35
        if _, ok := supportedPlugins[pluginName]; ok {
9✔
36
                panic("plugin " + pluginName + " already registered")
×
37
        }
38
        supportedPlugins[pluginName] = plugin
9✔
39
}
40

41
// RegisterPluginIfNotExists will register a SQL plugin only if a plugin with same name has not already been registered
42
func RegisterPluginIfNotExists(pluginName string, plugin sqlplugin.Plugin) {
×
43
        if _, ok := supportedPlugins[pluginName]; !ok {
×
44
                supportedPlugins[pluginName] = plugin
×
45
        }
×
46
}
47

48
// PluginRegistered returns true if plugin with given name has been registered, false otherwise
49
func PluginRegistered(pluginName string) bool {
×
50
        _, ok := supportedPlugins[pluginName]
×
51
        return ok
×
52
}
×
53

54
// GetRegisteredPluginNames returns the list of registered plugin names
55
func GetRegisteredPluginNames() []string {
×
56
        var plugins []string
×
57
        for k := range supportedPlugins {
×
58
                plugins = append(plugins, k)
×
59
        }
×
60
        sort.Strings(plugins)
×
61
        return plugins
×
62
}
63

64
// NewSQLDB creates a returns a reference to a logical connection to the
65
// underlying SQL database. The returned object is to tied to a single
66
// SQL database and the object can be used to perform CRUD operations on
67
// the tables in the database
68
func NewSQLDB(cfg *config.SQL) (sqlplugin.DB, error) {
74✔
69
        plugin, ok := supportedPlugins[cfg.PluginName]
74✔
70

74✔
71
        if !ok {
74✔
72
                return nil, fmt.Errorf("not supported plugin %v, only supported: %v", cfg.PluginName, supportedPlugins)
×
73
        }
×
74

75
        return plugin.CreateDB(cfg)
74✔
76
}
77

78
// NewSQLAdminDB returns a AdminDB
79
func NewSQLAdminDB(cfg *config.SQL) (sqlplugin.AdminDB, error) {
34✔
80
        plugin, ok := supportedPlugins[cfg.PluginName]
34✔
81

34✔
82
        if !ok {
34✔
83
                return nil, fmt.Errorf("not supported plugin %v, only supported: %v", cfg.PluginName, supportedPlugins)
×
84
        }
×
85

86
        return plugin.CreateAdminDB(cfg)
34✔
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc