gitleaks_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "path"
  7. "regexp"
  8. "strings"
  9. "testing"
  10. "github.com/franela/goblin"
  11. git "gopkg.in/src-d/go-git.v4"
  12. "gopkg.in/src-d/go-git.v4/storage/memory"
  13. )
  14. const testWhitelistCommit = `
  15. [[regexes]]
  16. description = "AWS"
  17. regex = '''AKIA[0-9A-Z]{16}'''
  18. [whitelist]
  19. commits = [
  20. "eaeffdc65b4c73ccb67e75d96bd8743be2c85973",
  21. ]
  22. `
  23. const testWhitelistFile = `
  24. [[regexes]]
  25. description = "AWS"
  26. regex = '''AKIA[0-9A-Z]{16}'''
  27. [whitelist]
  28. files = [
  29. ".go",
  30. ]
  31. `
  32. const testWhitelistBranch = `
  33. [[regexes]]
  34. description = "AWS"
  35. regex = '''AKIA[0-9A-Z]{16}'''
  36. [whitelist]
  37. branches = [
  38. "origin/master",
  39. ]
  40. `
  41. const testWhitelistRegex = `
  42. [[regexes]]
  43. description = "AWS"
  44. regex = '''AKIA[0-9A-Z]{16}'''
  45. [whitelist]
  46. regexes= [
  47. "AKIA",
  48. ]
  49. `
  50. var benchmarkRepo *Repo
  51. var benchmarkLeaksRepo *Repo
  52. func getBenchmarkLeaksRepo() *Repo {
  53. if benchmarkLeaksRepo != nil {
  54. return benchmarkLeaksRepo
  55. }
  56. leaksR, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
  57. URL: "https://github.com/gitleakstest/gronit.git",
  58. })
  59. benchmarkLeaksRepo = &Repo{
  60. repository: leaksR,
  61. }
  62. return benchmarkLeaksRepo
  63. }
  64. func getBenchmarkRepo() *Repo {
  65. if benchmarkRepo != nil {
  66. return benchmarkRepo
  67. }
  68. bmRepo, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
  69. URL: "https://github.com/apple/swift-package-manager.git",
  70. })
  71. benchmarkRepo = &Repo{
  72. repository: bmRepo,
  73. }
  74. return benchmarkRepo
  75. }
  76. func TestGetRepo(t *testing.T) {
  77. var err error
  78. dir, err = ioutil.TempDir("", "gitleaksTestRepo")
  79. defer os.RemoveAll(dir)
  80. if err != nil {
  81. panic(err)
  82. }
  83. _, err = git.PlainClone(dir, false, &git.CloneOptions{
  84. URL: "https://github.com/gitleakstest/gronit",
  85. })
  86. if err != nil {
  87. panic(err)
  88. }
  89. var tests = []struct {
  90. testOpts Options
  91. description string
  92. expectedErrMsg string
  93. }{
  94. {
  95. testOpts: Options{
  96. Repo: "https://github.com/gitleakstest/gronit",
  97. },
  98. description: "test plain clone remote repo",
  99. expectedErrMsg: "",
  100. },
  101. {
  102. testOpts: Options{
  103. Repo: "https://github.com/gitleakstest/gronit",
  104. Disk: true,
  105. },
  106. description: "test on disk clone remote repo",
  107. expectedErrMsg: "",
  108. },
  109. {
  110. testOpts: Options{
  111. RepoPath: dir,
  112. },
  113. description: "test local clone repo",
  114. expectedErrMsg: "",
  115. },
  116. {
  117. testOpts: Options{
  118. Repo: "https://github.com/gitleakstest/nope",
  119. },
  120. description: "test no repo",
  121. expectedErrMsg: "authentication required",
  122. },
  123. {
  124. testOpts: Options{
  125. Repo: "https://github.com/gitleakstest/private",
  126. IncludePrivate: true,
  127. },
  128. description: "test private repo",
  129. expectedErrMsg: "invalid auth method",
  130. },
  131. {
  132. testOpts: Options{
  133. Repo: "https://github.com/gitleakstest/private",
  134. IncludePrivate: true,
  135. Disk: true,
  136. },
  137. description: "test private repo",
  138. expectedErrMsg: "invalid auth method",
  139. },
  140. }
  141. g := goblin.Goblin(t)
  142. for _, test := range tests {
  143. g.Describe("TestGetRepo", func() {
  144. g.It(test.description, func() {
  145. opts = test.testOpts
  146. _, err := getRepo()
  147. if err != nil {
  148. g.Assert(err.Error()).Equal(test.expectedErrMsg)
  149. }
  150. })
  151. })
  152. }
  153. }
  154. func TestStartAudit(t *testing.T) {
  155. err := loadToml()
  156. configsDir := testTomlLoader()
  157. defer os.RemoveAll(configsDir)
  158. dir, err = ioutil.TempDir("", "gitleaksTestOwner")
  159. defer os.RemoveAll(dir)
  160. if err != nil {
  161. panic(err)
  162. }
  163. git.PlainClone(dir+"/gronit", false, &git.CloneOptions{
  164. URL: "https://github.com/gitleakstest/gronit",
  165. })
  166. git.PlainClone(dir+"/h1domains", false, &git.CloneOptions{
  167. URL: "https://github.com/gitleakstest/h1domains",
  168. })
  169. var tests = []struct {
  170. testOpts Options
  171. description string
  172. expectedErrMsg string
  173. numLeaks int
  174. }{
  175. {
  176. testOpts: Options{
  177. GithubUser: "gitleakstest",
  178. },
  179. description: "test github user",
  180. numLeaks: 2,
  181. expectedErrMsg: "",
  182. },
  183. {
  184. testOpts: Options{
  185. GithubUser: "gitleakstest",
  186. Disk: true,
  187. },
  188. description: "test github user on disk ",
  189. numLeaks: 2,
  190. expectedErrMsg: "",
  191. },
  192. {
  193. testOpts: Options{
  194. GithubOrg: "gitleakstestorg",
  195. },
  196. description: "test github org",
  197. numLeaks: 2,
  198. expectedErrMsg: "",
  199. },
  200. {
  201. testOpts: Options{
  202. GithubOrg: "gitleakstestorg",
  203. IncludePrivate: true,
  204. },
  205. description: "test private org no ssh",
  206. numLeaks: 0,
  207. expectedErrMsg: "no ssh auth available",
  208. },
  209. {
  210. testOpts: Options{
  211. GithubOrg: "gitleakstestorg",
  212. Disk: true,
  213. },
  214. description: "test org on disk",
  215. numLeaks: 2,
  216. expectedErrMsg: "",
  217. },
  218. {
  219. testOpts: Options{
  220. GithubOrg: "gitleakstestorg",
  221. IncludePrivate: true,
  222. Disk: true,
  223. },
  224. description: "test private org on disk no ssh",
  225. numLeaks: 0,
  226. expectedErrMsg: "no ssh auth available",
  227. },
  228. {
  229. testOpts: Options{
  230. OwnerPath: dir,
  231. },
  232. description: "test owner path",
  233. numLeaks: 2,
  234. expectedErrMsg: "",
  235. },
  236. }
  237. g := goblin.Goblin(t)
  238. for _, test := range tests {
  239. g.Describe("TestStartAudit", func() {
  240. g.It(test.description, func() {
  241. opts = test.testOpts
  242. leaks, err := startAudits()
  243. if err != nil {
  244. g.Assert(err.Error()).Equal(test.expectedErrMsg)
  245. }
  246. g.Assert(len(leaks)).Equal(test.numLeaks)
  247. })
  248. })
  249. }
  250. }
  251. func TestWriteReport(t *testing.T) {
  252. tmpDir, _ := ioutil.TempDir("", "reportDir")
  253. reportJSON := path.Join(tmpDir, "report.json")
  254. reportCSV := path.Join(tmpDir, "report.csv")
  255. defer os.RemoveAll(tmpDir)
  256. leaks := []Leak{
  257. {
  258. Line: "eat",
  259. Commit: "your",
  260. Offender: "veggies",
  261. Type: "and",
  262. Message: "get",
  263. Author: "some",
  264. File: "sleep",
  265. Branch: "thxu",
  266. },
  267. }
  268. var tests = []struct {
  269. leaks []Leak
  270. reportFile string
  271. fileName string
  272. description string
  273. testOpts Options
  274. }{
  275. {
  276. leaks: leaks,
  277. reportFile: reportJSON,
  278. fileName: "report.json",
  279. description: "can we write a file",
  280. testOpts: Options{
  281. Report: reportJSON,
  282. },
  283. },
  284. {
  285. leaks: leaks,
  286. reportFile: reportCSV,
  287. fileName: "report.csv",
  288. description: "can we write a file",
  289. testOpts: Options{
  290. Report: reportCSV,
  291. CSV: true,
  292. },
  293. },
  294. }
  295. g := goblin.Goblin(t)
  296. for _, test := range tests {
  297. g.Describe("TestWriteReport", func() {
  298. g.It(test.description, func() {
  299. opts = test.testOpts
  300. writeReport(test.leaks)
  301. f, _ := os.Stat(test.reportFile)
  302. g.Assert(f.Name()).Equal(test.fileName)
  303. })
  304. })
  305. }
  306. }
  307. func testTomlLoader() string {
  308. tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
  309. ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
  310. ioutil.WriteFile(path.Join(tmpDir, "branch"), []byte(testWhitelistBranch), 0644)
  311. ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
  312. ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
  313. return tmpDir
  314. }
  315. func TestAuditRepo(t *testing.T) {
  316. var leaks []Leak
  317. err := loadToml()
  318. configsDir := testTomlLoader()
  319. defer os.RemoveAll(configsDir)
  320. if err != nil {
  321. panic(err)
  322. }
  323. leaksR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
  324. URL: "https://github.com/gitleakstest/gronit.git",
  325. })
  326. if err != nil {
  327. panic(err)
  328. }
  329. leaksRepo := Repo{
  330. repository: leaksR,
  331. name: "gronit",
  332. }
  333. cleanR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
  334. URL: "https://github.com/gitleakstest/h1domains.git",
  335. })
  336. if err != nil {
  337. panic(err)
  338. }
  339. cleanRepo := Repo{
  340. repository: cleanR,
  341. name: "h1domains",
  342. }
  343. var tests = []struct {
  344. testOpts Options
  345. description string
  346. expectedErrMsg string
  347. numLeaks int
  348. repo Repo
  349. whiteListFiles []*regexp.Regexp
  350. whiteListCommits map[string]bool
  351. whiteListBranches []string
  352. whiteListRegexes []*regexp.Regexp
  353. configPath string
  354. }{
  355. {
  356. repo: leaksRepo,
  357. description: "two leaks present",
  358. numLeaks: 2,
  359. },
  360. {
  361. repo: leaksRepo,
  362. description: "two leaks present limit goroutines",
  363. numLeaks: 2,
  364. testOpts: Options{
  365. MaxGoRoutines: 2,
  366. },
  367. },
  368. {
  369. repo: leaksRepo,
  370. description: "audit specific bad branch",
  371. numLeaks: 2,
  372. testOpts: Options{
  373. Branch: "master",
  374. },
  375. },
  376. {
  377. repo: leaksRepo,
  378. description: "audit specific good branch",
  379. numLeaks: 0,
  380. testOpts: Options{
  381. Branch: "dev",
  382. },
  383. },
  384. {
  385. repo: leaksRepo,
  386. description: "audit all branch",
  387. numLeaks: 6,
  388. testOpts: Options{
  389. AuditAllRefs: true,
  390. },
  391. },
  392. {
  393. repo: leaksRepo,
  394. description: "audit all branch whitelist 1",
  395. numLeaks: 4,
  396. testOpts: Options{
  397. AuditAllRefs: true,
  398. },
  399. whiteListBranches: []string{
  400. "origin/master",
  401. },
  402. },
  403. {
  404. repo: leaksRepo,
  405. description: "two leaks present whitelist AWS.. no leaks",
  406. whiteListRegexes: []*regexp.Regexp{
  407. regexp.MustCompile("AKIA"),
  408. },
  409. numLeaks: 0,
  410. },
  411. {
  412. repo: leaksRepo,
  413. description: "two leaks present limit goroutines",
  414. numLeaks: 2,
  415. },
  416. {
  417. repo: cleanRepo,
  418. description: "no leaks present",
  419. numLeaks: 0,
  420. },
  421. {
  422. repo: leaksRepo,
  423. description: "two leaks present whitelist go files",
  424. whiteListFiles: []*regexp.Regexp{
  425. regexp.MustCompile(".go"),
  426. },
  427. numLeaks: 0,
  428. },
  429. {
  430. // note this double counts the first commit since we are whitelisting
  431. // a "bad" first commit
  432. repo: leaksRepo,
  433. description: "two leaks present whitelist bad commit",
  434. whiteListCommits: map[string]bool{
  435. "eaeffdc65b4c73ccb67e75d96bd8743be2c85973": true,
  436. },
  437. numLeaks: 2,
  438. },
  439. {
  440. repo: leaksRepo,
  441. description: "redact",
  442. testOpts: Options{
  443. Redact: true,
  444. },
  445. numLeaks: 2,
  446. },
  447. {
  448. repo: leaksRepo,
  449. description: "toml whitelist regex",
  450. configPath: path.Join(configsDir, "regex"),
  451. numLeaks: 0,
  452. },
  453. {
  454. repo: leaksRepo,
  455. description: "toml whitelist branch",
  456. configPath: path.Join(configsDir, "branch"),
  457. testOpts: Options{
  458. AuditAllRefs: true,
  459. },
  460. numLeaks: 4,
  461. },
  462. {
  463. repo: leaksRepo,
  464. description: "toml whitelist file",
  465. configPath: path.Join(configsDir, "file"),
  466. numLeaks: 0,
  467. },
  468. {
  469. // note this double counts the first commit since we are whitelisting
  470. // a "bad" first commit
  471. repo: leaksRepo,
  472. description: "toml whitelist commit",
  473. configPath: path.Join(configsDir, "commit"),
  474. numLeaks: 2,
  475. },
  476. }
  477. whiteListCommits = make(map[string]bool)
  478. g := goblin.Goblin(t)
  479. for _, test := range tests {
  480. g.Describe("TestAuditRepo", func() {
  481. g.It(test.description, func() {
  482. opts = test.testOpts
  483. // settin da globs
  484. if test.whiteListFiles != nil {
  485. whiteListFiles = test.whiteListFiles
  486. } else {
  487. whiteListFiles = nil
  488. }
  489. if test.whiteListCommits != nil {
  490. whiteListCommits = test.whiteListCommits
  491. } else {
  492. whiteListCommits = nil
  493. }
  494. if test.whiteListBranches != nil {
  495. whiteListBranches = test.whiteListBranches
  496. } else {
  497. whiteListBranches = nil
  498. }
  499. if test.whiteListRegexes != nil {
  500. whiteListRegexes = test.whiteListRegexes
  501. } else {
  502. whiteListRegexes = nil
  503. }
  504. // config paths
  505. if test.configPath != "" {
  506. os.Setenv("GITLEAKS_CONFIG", test.configPath)
  507. loadToml()
  508. }
  509. leaks, err = auditRepo(test.repo)
  510. if opts.Redact {
  511. g.Assert(leaks[0].Offender).Equal("REDACTED")
  512. }
  513. g.Assert(len(leaks)).Equal(test.numLeaks)
  514. })
  515. })
  516. }
  517. }
  518. func TestOptionGuard(t *testing.T) {
  519. var tests = []struct {
  520. testOpts Options
  521. githubToken bool
  522. description string
  523. expectedErrMsg string
  524. expectedErrMsgFuzzy string
  525. }{
  526. {
  527. testOpts: Options{},
  528. description: "default no opts",
  529. expectedErrMsg: "",
  530. },
  531. {
  532. testOpts: Options{
  533. IncludePrivate: true,
  534. GithubOrg: "fakeOrg",
  535. },
  536. description: "private org no githubtoken",
  537. expectedErrMsg: "user/organization private repos require env var GITHUB_TOKEN to be set",
  538. githubToken: false,
  539. },
  540. {
  541. testOpts: Options{
  542. IncludePrivate: true,
  543. GithubUser: "fakeUser",
  544. },
  545. description: "private user no githubtoken",
  546. expectedErrMsg: "user/organization private repos require env var GITHUB_TOKEN to be set",
  547. githubToken: false,
  548. },
  549. {
  550. testOpts: Options{
  551. IncludePrivate: true,
  552. GithubUser: "fakeUser",
  553. GithubOrg: "fakeOrg",
  554. },
  555. description: "double owner",
  556. expectedErrMsg: "github user and organization set",
  557. },
  558. {
  559. testOpts: Options{
  560. IncludePrivate: true,
  561. GithubOrg: "fakeOrg",
  562. OwnerPath: "/dev/null",
  563. },
  564. description: "local and remote target",
  565. expectedErrMsg: "github organization set and local owner path",
  566. },
  567. {
  568. testOpts: Options{
  569. IncludePrivate: true,
  570. GithubUser: "fakeUser",
  571. OwnerPath: "/dev/null",
  572. },
  573. description: "local and remote target",
  574. expectedErrMsg: "github user set and local owner path",
  575. },
  576. {
  577. testOpts: Options{
  578. GithubUser: "fakeUser",
  579. SingleSearch: "*/./....",
  580. },
  581. description: "single search invalid regex gaurd",
  582. expectedErrMsgFuzzy: "unable to compile regex: */./...., ",
  583. },
  584. {
  585. testOpts: Options{
  586. GithubUser: "fakeUser",
  587. SingleSearch: "mystring",
  588. },
  589. description: "single search regex gaurd",
  590. expectedErrMsg: "",
  591. },
  592. }
  593. g := goblin.Goblin(t)
  594. for _, test := range tests {
  595. g.Describe("Test Option Gaurd", func() {
  596. g.It(test.description, func() {
  597. os.Clearenv()
  598. opts = test.testOpts
  599. if test.githubToken {
  600. os.Setenv("GITHUB_TOKEN", "fakeToken")
  601. }
  602. err := optsGuard()
  603. if err != nil {
  604. if test.expectedErrMsgFuzzy != "" {
  605. g.Assert(strings.Contains(err.Error(), test.expectedErrMsgFuzzy)).Equal(true)
  606. } else {
  607. g.Assert(err.Error()).Equal(test.expectedErrMsg)
  608. }
  609. } else {
  610. g.Assert("").Equal(test.expectedErrMsg)
  611. }
  612. })
  613. })
  614. }
  615. }
  616. func TestLoadToml(t *testing.T) {
  617. tmpDir, _ := ioutil.TempDir("", "gitleaksTestConfigDir")
  618. defer os.RemoveAll(tmpDir)
  619. err := ioutil.WriteFile(path.Join(tmpDir, "gitleaksConfig"), []byte(defaultConfig), 0644)
  620. if err != nil {
  621. panic(err)
  622. }
  623. configPath := path.Join(tmpDir, "gitleaksConfig")
  624. noConfigPath := path.Join(tmpDir, "gitleaksConfigNope")
  625. var tests = []struct {
  626. testOpts Options
  627. description string
  628. configPath string
  629. expectedErrMsg string
  630. singleSearch bool
  631. }{
  632. {
  633. testOpts: Options{
  634. ConfigPath: configPath,
  635. },
  636. description: "path to config",
  637. },
  638. {
  639. testOpts: Options{},
  640. description: "env var path to no config",
  641. singleSearch: true,
  642. },
  643. {
  644. testOpts: Options{
  645. ConfigPath: noConfigPath,
  646. },
  647. description: "no path to config",
  648. expectedErrMsg: fmt.Sprintf("no gitleaks config at %s", noConfigPath),
  649. },
  650. {
  651. testOpts: Options{},
  652. description: "env var path to config",
  653. configPath: configPath,
  654. expectedErrMsg: "",
  655. },
  656. {
  657. testOpts: Options{},
  658. description: "env var path to no config",
  659. configPath: noConfigPath,
  660. expectedErrMsg: fmt.Sprintf("problem loading config: open %s: no such file or directory", noConfigPath),
  661. },
  662. }
  663. g := goblin.Goblin(t)
  664. for _, test := range tests {
  665. g.Describe("TestLoadToml", func() {
  666. g.It(test.description, func() {
  667. opts = test.testOpts
  668. if test.singleSearch {
  669. singleSearchRegex = regexp.MustCompile("test")
  670. } else {
  671. singleSearchRegex = nil
  672. }
  673. if test.configPath != "" {
  674. os.Setenv("GITLEAKS_CONFIG", test.configPath)
  675. } else {
  676. os.Clearenv()
  677. }
  678. err := loadToml()
  679. if err != nil {
  680. g.Assert(err.Error()).Equal(test.expectedErrMsg)
  681. } else {
  682. g.Assert("").Equal(test.expectedErrMsg)
  683. }
  684. })
  685. })
  686. }
  687. }
  688. func BenchmarkAuditRepo1Proc(b *testing.B) {
  689. loadToml()
  690. opts.MaxGoRoutines = 1
  691. benchmarkRepo = getBenchmarkRepo()
  692. for n := 0; n < b.N; n++ {
  693. auditRepo(*benchmarkRepo)
  694. }
  695. }
  696. func BenchmarkAuditRepo2Proc(b *testing.B) {
  697. loadToml()
  698. opts.MaxGoRoutines = 2
  699. benchmarkRepo = getBenchmarkRepo()
  700. for n := 0; n < b.N; n++ {
  701. auditRepo(*benchmarkRepo)
  702. }
  703. }
  704. func BenchmarkAuditRepo4Proc(b *testing.B) {
  705. loadToml()
  706. opts.MaxGoRoutines = 4
  707. benchmarkRepo = getBenchmarkRepo()
  708. for n := 0; n < b.N; n++ {
  709. auditRepo(*benchmarkRepo)
  710. }
  711. }
  712. func BenchmarkAuditRepo8Proc(b *testing.B) {
  713. loadToml()
  714. opts.MaxGoRoutines = 8
  715. benchmarkRepo = getBenchmarkRepo()
  716. for n := 0; n < b.N; n++ {
  717. auditRepo(*benchmarkRepo)
  718. }
  719. }
  720. func BenchmarkAuditRepo10Proc(b *testing.B) {
  721. loadToml()
  722. opts.MaxGoRoutines = 10
  723. benchmarkRepo = getBenchmarkRepo()
  724. for n := 0; n < b.N; n++ {
  725. auditRepo(*benchmarkRepo)
  726. }
  727. }
  728. func BenchmarkAuditRepo100Proc(b *testing.B) {
  729. loadToml()
  730. opts.MaxGoRoutines = 100
  731. benchmarkRepo = getBenchmarkRepo()
  732. for n := 0; n < b.N; n++ {
  733. auditRepo(*benchmarkRepo)
  734. }
  735. }
  736. func BenchmarkAuditRepo1000Proc(b *testing.B) {
  737. loadToml()
  738. opts.MaxGoRoutines = 1000
  739. benchmarkRepo = getBenchmarkRepo()
  740. for n := 0; n < b.N; n++ {
  741. auditRepo(*benchmarkRepo)
  742. }
  743. }
  744. func BenchmarkAuditRepo10000Proc(b *testing.B) {
  745. loadToml()
  746. opts.MaxGoRoutines = 10000
  747. benchmarkRepo = getBenchmarkRepo()
  748. for n := 0; n < b.N; n++ {
  749. auditRepo(*benchmarkRepo)
  750. }
  751. }
  752. func BenchmarkAuditRepo100000Proc(b *testing.B) {
  753. loadToml()
  754. opts.MaxGoRoutines = 100000
  755. benchmarkRepo = getBenchmarkRepo()
  756. for n := 0; n < b.N; n++ {
  757. auditRepo(*benchmarkRepo)
  758. }
  759. }
  760. func BenchmarkAuditLeakRepo1Proc(b *testing.B) {
  761. loadToml()
  762. opts.MaxGoRoutines = 1
  763. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  764. for n := 0; n < b.N; n++ {
  765. auditRepo(*benchmarkLeaksRepo)
  766. }
  767. }
  768. func BenchmarkAuditLeakRepo2Proc(b *testing.B) {
  769. loadToml()
  770. opts.MaxGoRoutines = 2
  771. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  772. for n := 0; n < b.N; n++ {
  773. auditRepo(*benchmarkLeaksRepo)
  774. }
  775. }
  776. func BenchmarkAuditLeakRepo4Proc(b *testing.B) {
  777. loadToml()
  778. opts.MaxGoRoutines = 4
  779. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  780. for n := 0; n < b.N; n++ {
  781. auditRepo(*benchmarkLeaksRepo)
  782. }
  783. }
  784. func BenchmarkAuditLeakRepo8Proc(b *testing.B) {
  785. loadToml()
  786. opts.MaxGoRoutines = 8
  787. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  788. for n := 0; n < b.N; n++ {
  789. auditRepo(*benchmarkLeaksRepo)
  790. }
  791. }
  792. func BenchmarkAuditLeakRepo10Proc(b *testing.B) {
  793. loadToml()
  794. opts.MaxGoRoutines = 10
  795. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  796. for n := 0; n < b.N; n++ {
  797. auditRepo(*benchmarkLeaksRepo)
  798. }
  799. }
  800. func BenchmarkAuditLeakRepo100Proc(b *testing.B) {
  801. loadToml()
  802. opts.MaxGoRoutines = 100
  803. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  804. for n := 0; n < b.N; n++ {
  805. auditRepo(*benchmarkLeaksRepo)
  806. }
  807. }
  808. func BenchmarkAuditLeakRepo1000Proc(b *testing.B) {
  809. loadToml()
  810. opts.MaxGoRoutines = 1000
  811. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  812. for n := 0; n < b.N; n++ {
  813. auditRepo(*benchmarkLeaksRepo)
  814. }
  815. }
  816. func BenchmarkAuditLeakRepo10000Proc(b *testing.B) {
  817. loadToml()
  818. opts.MaxGoRoutines = 10000
  819. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  820. for n := 0; n < b.N; n++ {
  821. auditRepo(*benchmarkLeaksRepo)
  822. }
  823. }
  824. func BenchmarkAuditLeakRepo100000Proc(b *testing.B) {
  825. loadToml()
  826. opts.MaxGoRoutines = 100000
  827. benchmarkLeaksRepo = getBenchmarkLeaksRepo()
  828. for n := 0; n < b.N; n++ {
  829. auditRepo(*benchmarkLeaksRepo)
  830. }
  831. }