options_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestNextInt(t *testing.T) {
  6. args := []string{"-c", "10"}
  7. i := 0
  8. opts, err := defaultOptions()
  9. if err != nil {
  10. t.Error()
  11. }
  12. n := opts.nextInt(args, &i)
  13. if n != 10 {
  14. t.Error()
  15. }
  16. }
  17. func TestNextString(t *testing.T) {
  18. args := []string{"--fake", "flag"}
  19. i := 0
  20. opts, err := defaultOptions()
  21. if err != nil {
  22. t.Error()
  23. }
  24. n := opts.nextString(args, &i)
  25. if n != "flag" {
  26. t.Error()
  27. }
  28. }
  29. func TestOptString(t *testing.T) {
  30. opts, err := defaultOptions()
  31. if err != nil {
  32. t.Error()
  33. }
  34. match, n := opts.optString("--fake=flag", "--fake=")
  35. if !match || n != "flag" {
  36. t.Error()
  37. }
  38. }
  39. func TestOptInt(t *testing.T) {
  40. opts, err := defaultOptions()
  41. if err != nil {
  42. t.Error()
  43. }
  44. match, n := opts.optInt("--fake=10", "--fake=")
  45. if !match || n != 10 {
  46. t.Error()
  47. }
  48. }
  49. func TestParseOptions(t *testing.T) {
  50. opts, err := defaultOptions()
  51. opts.URL = "github.com/sample"
  52. if err != nil {
  53. t.Error()
  54. }
  55. opts.RepoMode = false
  56. opts.UserMode = true
  57. opts.LocalMode = true
  58. err = opts.guards()
  59. if err == nil {
  60. t.Error()
  61. }
  62. opts.RepoMode = true
  63. opts.UserMode = false
  64. opts.LocalMode = false
  65. err = opts.guards()
  66. if err != nil {
  67. t.Error()
  68. }
  69. }
  70. func TestGithubTarget(t *testing.T) {
  71. if !isGithubTarget("github.com"){
  72. t.Error()
  73. }
  74. if !isGithubTarget("https://github.com/"){
  75. t.Error()
  76. }
  77. if !isGithubTarget("git@github.com:zricethezav/gitleaks.git"){
  78. t.Error()
  79. }
  80. }