Add possiblity to limit actions to tagged or named repository

This commit is contained in:
Mikołaj Pęczkowski 2021-11-07 14:05:45 +01:00
parent 5c98ab6554
commit 23e4547e52
11 changed files with 345 additions and 24 deletions

View file

@ -3,11 +3,36 @@ package app
import (
"fmt"
"os"
"reflect"
"testing"
"gitlab.com/revalus/grm/commands"
"gitlab.com/revalus/grm/config"
)
type FakeCommandToTest struct {
triggerError bool
triggerChanged bool
}
func (fk FakeCommandToTest) Command(repoCfg config.RepositoryConfig, cmdStatus chan commands.CommandStatus) {
status := commands.CommandStatus{
Name: repoCfg.Name,
Changed: false,
Message: "response from fake command",
Error: false,
}
if fk.triggerError {
status.Error = true
}
if fk.triggerChanged {
status.Changed = true
}
cmdStatus <- status
}
func prepareConfigContent() (string, string) {
checkErrorDuringPreparation := func(err error) {
if err != nil {
@ -35,7 +60,9 @@ func prepareConfigContent() (string, string) {
yamlConfig := fmt.Sprintf(`
workspace: %v
repositories:
- src: "https://github.com/golang/example.git"`, tempDir)
- src: "https://github.com/golang/example.git"
tags: ['example']
`, tempDir)
_, err = file.WriteString(yamlConfig)
@ -65,12 +92,12 @@ func TestParseApplication(t *testing.T) {
Name: "example",
Src: "https://github.com/golang/example.git",
Dest: "example",
Tags: []string{"example"},
}
if expectedRepo != grm.configuration.Repositories[0] {
if !reflect.DeepEqual(expectedRepo, grm.configuration.Repositories[0]) {
t.Errorf("Expected to get %v, instead of this got %v", expectedRepo, grm.configuration.Repositories[0])
}
}
func Example_test_sync_output() {
@ -90,5 +117,117 @@ func Example_test_sync_output() {
// Output:
// Info: Synchronizing repositories
// Info: All repositories are synced
// Info: Current version: 0.2.0
// Info: Current version: 0.3.0
}
func Example_limit_test_tags() {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitTags: []string{"example"},
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1", Tags: []string{"example"}},
{Name: "example2", Tags: []string{"example"}},
{Name: "notExample"},
},
},
console: ConsoleOutput{
Color: false,
},
}
fakeCommand := FakeCommandToTest{
triggerError: false,
triggerChanged: false,
}
grm.limitTags()
grm.runCommand(fakeCommand)
// Output:
// Repository "example1": response from fake command
// Repository "example2": response from fake command
}
func Example_limit_name() {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitName: "notExample",
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1", Tags: []string{"example"}},
{Name: "example2", Tags: []string{"example"}},
{Name: "notExample"},
},
},
console: ConsoleOutput{
Color: false,
},
}
fakeCommand := FakeCommandToTest{
triggerError: false,
triggerChanged: false,
}
grm.limitName()
grm.runCommand(fakeCommand)
// Output:
// Repository "notExample": response from fake command
}
func Example_run_with_limit_not_existing_name() {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitName: "not-existing-name",
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1", Tags: []string{"example"}},
{Name: "example2", Tags: []string{"example"}},
{Name: "notExample"},
},
},
console: ConsoleOutput{
Color: false,
},
}
grm.Run()
// Output:
// Error: no repository was found with the specified name
}
func Example_run_with_limit_not_existing_tags() {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitTags: []string{"not-existing-tag"},
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1", Tags: []string{"example"}},
{Name: "example2", Tags: []string{"example"}},
{Name: "notExample"},
},
},
console: ConsoleOutput{
Color: false,
},
}
grm.Run()
// Output:
// Error: no repository was found with the specified tags
}
func Example_test_status_output() {
grm := GitRepositoryManager{
configuration: config.Configuration{
Workspace: "/tmp",
},
cliArguments: config.CliArguments{
Status: true,
},
console: ConsoleOutput{
Color: false,
},
}
grm.Run()
// Output:
// Info: Current status of repositories
}