-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1333 from vrothberg/RUN-1772
containers.conf: add database backend option
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
// DBBackend determines which supported database backend Podman should use. | ||
type DBBackend int | ||
|
||
const ( | ||
// Unsupported database backend. Used as a sane base value for the type. | ||
DBBackendUnsupported DBBackend = iota | ||
// BoltDB backend. | ||
DBBackendBoltDB | ||
// SQLite backend. | ||
DBBackendSQLite | ||
|
||
stringBoltDB = "boltdb" | ||
stringSQLite = "sqlite" | ||
) | ||
|
||
// String returns the DBBackend's string representation. | ||
func (d DBBackend) String() string { | ||
switch d { | ||
case DBBackendBoltDB: | ||
return stringBoltDB | ||
case DBBackendSQLite: | ||
return stringSQLite | ||
default: | ||
return fmt.Sprintf("unsupported database backend: %d", d) | ||
} | ||
} | ||
|
||
// Validate returns whether the DBBackend is supported. | ||
func (d DBBackend) Validate() error { | ||
switch d { | ||
case DBBackendBoltDB, DBBackendSQLite: | ||
return nil | ||
default: | ||
return fmt.Errorf("unsupported database backend: %d", d) | ||
} | ||
} | ||
|
||
// ParseDBBackend parses the specified string into a DBBackend. | ||
// An error is return for unsupported backends. | ||
func ParseDBBackend(raw string) (DBBackend, error) { | ||
// NOTE: this function should be used for parsing the user-specified | ||
// values on Podman's CLI. | ||
switch raw { | ||
case stringBoltDB: | ||
return DBBackendBoltDB, nil | ||
case stringSQLite: | ||
return DBBackendSQLite, nil | ||
default: | ||
return DBBackendUnsupported, fmt.Errorf("unsupported database backend: %q", raw) | ||
} | ||
} | ||
|
||
// DBBackend returns the configured database backend. | ||
func (c *Config) DBBackend() (DBBackend, error) { | ||
return ParseDBBackend(c.Engine.DBBackend) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDBBackend(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
valid bool | ||
expected DBBackend | ||
}{ | ||
{stringBoltDB, true, DBBackendBoltDB}, | ||
{stringSQLite, true, DBBackendSQLite}, | ||
{"", false, DBBackendUnsupported}, | ||
{stringSQLite + " ", false, DBBackendUnsupported}, | ||
} | ||
|
||
for _, test := range tests { | ||
result, err := ParseDBBackend(test.input) | ||
if test.valid { | ||
require.NoError(t, err, "should parse %v", test) | ||
require.NoError(t, result.Validate(), "should validate %v", test) | ||
require.Equal(t, test.expected, result) | ||
} else { | ||
require.Error(t, err, "should NOT parse %v", test) | ||
require.Error(t, result.Validate(), "should NOT validate %v", test) | ||
require.Equal(t, test.expected, result) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters