-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor driver enum into database enum * implement docker manager singleton * remove duplicate testdata folder * refactor global constants into iota
- Loading branch information
1 parent
889e2e9
commit 51f8b4f
Showing
18 changed files
with
429 additions
and
18 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,35 @@ | ||
package global | ||
|
||
import "sync" | ||
|
||
type Database int | ||
|
||
const ( | ||
Postgres Database = iota | ||
MySql Database = iota | ||
) | ||
|
||
var toStr = map[Database]string{ | ||
Postgres: "postgres", | ||
MySql: "mysql", | ||
} | ||
|
||
var fromStr map[string]Database | ||
|
||
var initFromStrOnce sync.Once | ||
|
||
func initFromStr() { | ||
fromStr = make(map[string]Database, len(toStr)) | ||
for k, v := range toStr { | ||
fromStr[v] = k | ||
} | ||
} | ||
|
||
func (d Database) String() string { | ||
return toStr[d] | ||
} | ||
|
||
func (d *Database) FromStr(s string) { | ||
initFromStrOnce.Do(initFromStr) | ||
*d = fromStr[s] | ||
} |
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,39 @@ | ||
package global | ||
|
||
import ( | ||
"fmt" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Check Command", func() { | ||
var ( | ||
subject Database | ||
) | ||
|
||
Context("FromStr", func() { | ||
When("not used", func() { | ||
It("uses default value", func() { | ||
Expect(subject).To(Equal(Postgres)) | ||
}) | ||
}) | ||
|
||
for k, v := range toStr { | ||
When(fmt.Sprintf("str is %s", v), func() { | ||
subject.FromStr(v) | ||
It(fmt.Sprintf("updates to %s domain", v), func() { | ||
Expect(subject).To(Equal(k)) | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
Context("ToStr", func() { | ||
for k, v := range toStr { | ||
When(v, func() { | ||
subject = k | ||
Expect(fmt.Sprintf("%s", subject)).To(Equal(v)) | ||
}) | ||
} | ||
}) | ||
}) |
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
Oops, something went wrong.