Restructure project directories
Follow the standard of all go projects
This commit is contained in:
parent
741f18efd1
commit
5445ce1ccf
20 changed files with 39 additions and 42 deletions
83
internal/config/cmd_test.go
Normal file
83
internal/config/cmd_test.go
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetDefaultConfigDir(t *testing.T) {
|
||||
ud, _ := os.UserHomeDir()
|
||||
|
||||
desiredPath := fmt.Sprintf("%v/%v", ud, defaultConfigPath)
|
||||
|
||||
if getDefaultConfigDir() != desiredPath {
|
||||
t.Errorf("Expected to get %v, instead of this got %v", desiredPath, getDefaultConfigDir())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestParsingDefaultArguments(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName", "sync"}
|
||||
|
||||
parseResult, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err.Error())
|
||||
}
|
||||
|
||||
if parseResult.ConfigurationFile != getDefaultConfigDir() {
|
||||
t.Errorf("Default value for configurationFile should be %v, instead of this got %v", getDefaultConfigDir(), parseResult.ConfigurationFile)
|
||||
}
|
||||
|
||||
if parseResult.Sync != true {
|
||||
t.Errorf("Default value for configurationFile should be %v, instead of this got %v", true, parseResult.Sync)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsingWithoutCommand(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName", "--name", "test"}
|
||||
|
||||
results, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, not results: %v", results)
|
||||
}
|
||||
if err.Error() != errNoCommand {
|
||||
t.Errorf("Expected to get \"%v\", instead of this got \"%v\"", errNoCommand, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestParsingNothingProvided(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName"}
|
||||
|
||||
results, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, not results: %v", results)
|
||||
}
|
||||
|
||||
}
|
||||
func TestParsingNameAndTags(t *testing.T) {
|
||||
|
||||
// First item in os.Args is appPath, this have to be mocked
|
||||
fakeOSArgs := []string{"appName", "status", "--tag", "example", "--name", "example"}
|
||||
|
||||
results, err := ParseCliArguments("", "", fakeOSArgs)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Expected error, not results: %v", results)
|
||||
}
|
||||
|
||||
if err.Error() != errNameAndTagsTogether {
|
||||
t.Errorf("Expected to get \"%v\", instead of this got \"%v\"", errNameAndTagsTogether, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue