-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
386 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "testdata/fibonacci"] | ||
path = testdata/fibonacci | ||
url = https://htamada@bitbucket.org/htamada/fibonacci.git | ||
[submodule "testdata/helloworld"] | ||
path = testdata/helloworld | ||
url = https://htamada@bitbucket.org/htamada/helloworld.git |
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
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,72 @@ | ||
package add | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/tamada/rrh/common" | ||
) | ||
|
||
func rollback(f func()) { | ||
var config = common.OpenConfig() | ||
var db, _ = common.Open(config) | ||
defer db.StoreAndClose() | ||
|
||
f() | ||
} | ||
|
||
func TestHelpAndSynopsis(t *testing.T) { | ||
var command, _ = AddCommandFactory() | ||
if command.Synopsis() != "add repositories on the local path to RRH" { | ||
t.Error("synopsis did not match") | ||
} | ||
if command.Help() != `rrh add [OPTIONS] <REPOSITORY_PATHS...> | ||
OPTIONS | ||
-g, --group <GROUP> add repository to RRH database. | ||
ARGUMENTS | ||
REPOSITORY_PATHS the local path list of the git repositories` { | ||
t.Error("help did not match") | ||
} | ||
} | ||
|
||
func TestAddToTheSpecifiedGroup(t *testing.T) { | ||
os.Setenv(common.RrhConfigPath, "../testdata/config.json") | ||
os.Setenv(common.RrhDatabasePath, "../testdata/tmp.json") | ||
rollback(func() { | ||
var command, _ = AddCommandFactory() | ||
command.Run([]string{"--group", "group2", "../testdata/helloworld"}) | ||
|
||
var config = common.OpenConfig() | ||
var db, _ = common.Open(config) | ||
if !db.HasGroup("group2") { | ||
t.Error("group2: group not found") | ||
} | ||
if !db.HasRepository("helloworld") { | ||
t.Error("helloworld: repository not found") | ||
} | ||
if !db.HasRelation("group2", "helloworld") { | ||
t.Error("gruop2, and helloworld: the relation not found") | ||
} | ||
}) | ||
} | ||
|
||
func TestAddCommand_Run(t *testing.T) { | ||
os.Setenv(common.RrhConfigPath, "../testdata/config.json") | ||
os.Setenv(common.RrhDatabasePath, "../testdata/tmp.json") | ||
rollback(func() { | ||
var command, _ = AddCommandFactory() | ||
command.Run([]string{"../testdata/fibonacci"}) | ||
|
||
var config = common.OpenConfig() | ||
var db, _ = common.Open(config) | ||
if !db.HasGroup("no-group") { | ||
t.Error("no-group: group not found") | ||
} | ||
if !db.HasRepository("fibonacci") { | ||
t.Error("fibonacci: repository not found") | ||
} | ||
if !db.HasRelation("no-group", "fibonacci") { | ||
t.Error("no-group, and fibonacci: the relation not found") | ||
} | ||
}) | ||
} |
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.