Version control system wrapper allowing the developer to worry about only having to learn one command set to manage all types of repositories. Derivative of the Python project http://code.revolvingcow.com/RevolvingCow/pycode

app_test.go 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package cmd
  2. import (
  3. "bytes"
  4. "os"
  5. "testing"
  6. )
  7. // Test using an extension command
  8. func TestExtension(t *testing.T) {
  9. var buffer bytes.Buffer
  10. os.Setenv("CODE_VCS", "git")
  11. os.Setenv("CODE_GIT_CHECK", "branch")
  12. os.Setenv("CODE_GIT_INCOMING", "log ..@{u}")
  13. app := App{
  14. Args: []string{"incoming"},
  15. Stdin: &buffer,
  16. Stderr: &buffer,
  17. Stdout: &buffer,
  18. Directory: GetWorkingDirectory(),
  19. }
  20. err := app.Run()
  21. if err != nil {
  22. t.FailNow()
  23. }
  24. }
  25. // Test a raw command not currently defined but can pass through
  26. func TestRawCommand(t *testing.T) {
  27. var buffer bytes.Buffer
  28. os.Setenv("CODE_VCS", "git")
  29. os.Setenv("CODE_GIT_CHECK", "branch")
  30. app := App{
  31. Args: []string{"status"},
  32. Stdin: &buffer,
  33. Stderr: &buffer,
  34. Stdout: &buffer,
  35. Directory: GetWorkingDirectory(),
  36. }
  37. err := app.Run()
  38. if err != nil {
  39. t.FailNow()
  40. }
  41. }
  42. // Test behavior when a VCS "check" is not defined
  43. func TestMissingCheck(t *testing.T) {
  44. var buffer bytes.Buffer
  45. os.Setenv("CODE_VCS", "git")
  46. os.Unsetenv("CODE_GIT_CHECK")
  47. app := App{
  48. Args: []string{"status"},
  49. Stdin: &buffer,
  50. Stderr: &buffer,
  51. Stdout: &buffer,
  52. Directory: GetWorkingDirectory(),
  53. }
  54. err := app.Run()
  55. if err != nil {
  56. t.FailNow()
  57. }
  58. }
  59. // Test behavior when a subcommand is issued which does not exist
  60. func TestMissingCommand(t *testing.T) {
  61. var buffer bytes.Buffer
  62. os.Setenv("CODE_VCS", "git")
  63. os.Setenv("CODE_GIT_CHECK", "branch")
  64. app := App{
  65. Args: []string{"nonexistant", "command"},
  66. Stdin: &buffer,
  67. Stderr: &buffer,
  68. Stdout: &buffer,
  69. Directory: GetWorkingDirectory(),
  70. }
  71. err := app.Run()
  72. if err != nil {
  73. t.FailNow()
  74. }
  75. }
  76. // Test output if there is currently no VCS repository found
  77. func TestMissingRepository(t *testing.T) {
  78. var buffer bytes.Buffer
  79. os.Chdir(os.TempDir())
  80. os.Setenv("CODE_VCS", "git")
  81. os.Setenv("CODE_GIT_CHECK", "branch")
  82. app := App{
  83. Args: []string{"status"},
  84. Stdin: &buffer,
  85. Stderr: &buffer,
  86. Stdout: &buffer,
  87. Directory: GetWorkingDirectory(),
  88. }
  89. err := app.Run()
  90. if err == nil {
  91. t.FailNow()
  92. }
  93. }
  94. // Test handling of no arguments passed
  95. func TestNoArguments(t *testing.T) {
  96. var buffer bytes.Buffer
  97. os.Setenv("CODE_VCS", "git")
  98. os.Setenv("CODE_GIT_CHECK", "branch")
  99. app := App{
  100. Args: []string{},
  101. Stdin: &buffer,
  102. Stderr: &buffer,
  103. Stdout: &buffer,
  104. Directory: GetWorkingDirectory(),
  105. }
  106. err := app.Run()
  107. if err == nil {
  108. t.FailNow()
  109. }
  110. }
  111. // Test the creation of a new application
  112. func TestNewApp(t *testing.T) {
  113. app := NewApp()
  114. if app.Stdin == nil {
  115. t.Fail()
  116. }
  117. if app.Stderr == nil {
  118. t.Fail()
  119. }
  120. if app.Stdout == nil {
  121. t.Fail()
  122. }
  123. if app.Directory == "" {
  124. t.Fail()
  125. }
  126. }