repo_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func TestNewLocalRepo(t *testing.T) {
  7. r := newLocalRepo("")
  8. if r.path != "" {
  9. t.Error()
  10. }
  11. r = newLocalRepo("some/path")
  12. if r.name != "path" || r.path != "some/path" {
  13. t.Error()
  14. }
  15. }
  16. func TestWriteReport(t *testing.T) {
  17. opts, _ = defaultOptions()
  18. r := newRepo("fakerepo", "github.com", "")
  19. r.leaks = []Leak{*sampleLeak(), *sampleLeak()}
  20. r.writeReport(r.leaks)
  21. if _, err := os.Stat("fakerepo_leaks.json"); os.IsNotExist(err) {
  22. t.Error()
  23. } else {
  24. os.Remove("fakerepo_leaks.json")
  25. }
  26. }
  27. func TestAudit(t *testing.T) {
  28. opts, _ = defaultOptions()
  29. opts.RepoMode = true
  30. opts.Tmp = true
  31. opts.URL = "https://github.com/zricethezav/gronit"
  32. owner := newOwner()
  33. r := newRepo("gronit", opts.URL, owner.path)
  34. leaksPst, _ := r.audit()
  35. if !leaksPst {
  36. // TODO setup actual test repo
  37. t.Error()
  38. }
  39. // new owner
  40. opts.URL = "https://github.com/kelseyhightower/nocode"
  41. owner = newOwner()
  42. r = newRepo("nocode", opts.URL, owner.path)
  43. leaksPst, _ = r.audit()
  44. if leaksPst {
  45. t.Error()
  46. }
  47. }
  48. func sampleLeak() *Leak {
  49. return &Leak{
  50. Line: "yoo",
  51. Commit: "mycommit",
  52. Offender: "oh boy",
  53. Reason: "hello",
  54. Msg: "msg",
  55. Time: "time",
  56. Author: "lol",
  57. RepoURL: "yooo",
  58. }
  59. }