Просмотр исходного кода

adding report-format to tests since we dont parse flags

zach rice 6 лет назад
Родитель
Сommit
f3eac0c958
1 измененных файлов с 63 добавлено и 45 удалено
  1. 63 45
      audit/audit_test.go

+ 63 - 45
audit/audit_test.go

@@ -29,136 +29,152 @@ func TestAudit(t *testing.T) {
 		{
 		{
 			description: "test local repo one aws leak",
 			description: "test local repo one aws leak",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_local_repo_one_aws_leak.json.got",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_local_repo_one_aws_leak.json.got",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_one_aws_leak.json",
 			wantPath: "../test_data/test_local_repo_one_aws_leak.json",
 		},
 		},
 		{
 		{
 			description: "test local repo one aws leak threaded",
 			description: "test local repo one aws leak threaded",
 			opts: options.Options{
 			opts: options.Options{
-				Threads:  runtime.GOMAXPROCS(0),
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_local_repo_one_aws_leak.json.got",
+				Threads:      runtime.GOMAXPROCS(0),
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_local_repo_one_aws_leak.json.got",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_one_aws_leak.json",
 			wantPath: "../test_data/test_local_repo_one_aws_leak.json",
 		},
 		},
 		{
 		{
 			description: "test non existent repo",
 			description: "test non existent repo",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/no_repo_here",
+				RepoPath:     "../test_data/test_repos/no_repo_here",
+				ReportFormat: "json",
 			},
 			},
 			emptyRepo: true,
 			emptyRepo: true,
 		},
 		},
 		{
 		{
 			description: "test local repo one aws leak whitelisted",
 			description: "test local repo one aws leak whitelisted",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Config:   "../test_data/test_configs/aws_key_whitelist_python_files.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				ReportFormat: "json",
+				Config:       "../test_data/test_configs/aws_key_whitelist_python_files.toml",
 			},
 			},
 			wantEmpty: true,
 			wantEmpty: true,
 		},
 		},
 		{
 		{
 			description: "test local repo two leaks",
 			description: "test local repo two leaks",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_2",
-				Report:   "../test_data/test_local_repo_two_leaks.json.got",
+				RepoPath:     "../test_data/test_repos/test_repo_2",
+				Report:       "../test_data/test_local_repo_two_leaks.json.got",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_two_leaks.json",
 			wantPath: "../test_data/test_local_repo_two_leaks.json",
 		},
 		},
 		{
 		{
 			description: "test local repo two leaks globally whitelisted",
 			description: "test local repo two leaks globally whitelisted",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_2",
-				Config:   "../test_data/test_configs/aws_key_global_whitelist_file.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_2",
+				Config:       "../test_data/test_configs/aws_key_global_whitelist_file.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantEmpty: true,
 			wantEmpty: true,
 		},
 		},
 		{
 		{
 			description: "test local repo two leaks whitelisted",
 			description: "test local repo two leaks whitelisted",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_2",
-				Config:   "../test_data/test_configs/aws_key_whitelist_files.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_2",
+				Config:       "../test_data/test_configs/aws_key_whitelist_files.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantEmpty: true,
 			wantEmpty: true,
 		},
 		},
 		{
 		{
 			description: "test local repo three leaks dev branch",
 			description: "test local repo three leaks dev branch",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_3",
-				Report:   "../test_data/test_local_repo_three_leaks.json.got",
-				Config:   "../test_data/test_configs/aws_key.toml",
-				Branch:   "dev",
+				RepoPath:     "../test_data/test_repos/test_repo_3",
+				Report:       "../test_data/test_local_repo_three_leaks.json.got",
+				Config:       "../test_data/test_configs/aws_key.toml",
+				Branch:       "dev",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_three_leaks.json",
 			wantPath: "../test_data/test_local_repo_three_leaks.json",
 		},
 		},
 		{
 		{
 			description: "test local repo branch does not exist",
 			description: "test local repo branch does not exist",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_3",
-				Branch:   "nobranch",
+				RepoPath:     "../test_data/test_repos/test_repo_3",
+				Branch:       "nobranch",
+				ReportFormat: "json",
 			},
 			},
 			wantEmpty: true,
 			wantEmpty: true,
 		},
 		},
 		{
 		{
 			description: "test local repo one aws leak single commit",
 			description: "test local repo one aws leak single commit",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_local_repo_one_aws_leak_commit.json.got",
-				Commit:   "6557c92612d3b35979bd426d429255b3bf9fab74",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_local_repo_one_aws_leak_commit.json.got",
+				Commit:       "6557c92612d3b35979bd426d429255b3bf9fab74",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_one_aws_leak_commit.json",
 			wantPath: "../test_data/test_local_repo_one_aws_leak_commit.json",
 		},
 		},
 		{
 		{
 			description: "test local repo one aws leak AND leak on python files",
 			description: "test local repo one aws leak AND leak on python files",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_local_repo_one_aws_leak_and_file_leak.json.got",
-				Config:   "../test_data/test_configs/aws_key_file_regex.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_local_repo_one_aws_leak_and_file_leak.json.got",
+				Config:       "../test_data/test_configs/aws_key_file_regex.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_one_aws_leak_and_file_leak.json",
 			wantPath: "../test_data/test_local_repo_one_aws_leak_and_file_leak.json",
 		},
 		},
 		{
 		{
 			description: "test owner path",
 			description: "test owner path",
 			opts: options.Options{
 			opts: options.Options{
-				OwnerPath: "../test_data/test_repos/",
-				Report:    "../test_data/test_local_owner_aws_leak.json.got",
+				OwnerPath:    "../test_data/test_repos/",
+				Report:       "../test_data/test_local_owner_aws_leak.json.got",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_owner_aws_leak.json",
 			wantPath: "../test_data/test_local_owner_aws_leak.json",
 		},
 		},
 		{
 		{
 			description: "test entropy",
 			description: "test entropy",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_entropy.json.got",
-				Config:   "../test_data/test_configs/entropy.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_entropy.json.got",
+				Config:       "../test_data/test_configs/entropy.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_entropy.json",
 			wantPath: "../test_data/test_entropy.json",
 		},
 		},
 		{
 		{
 			description: "test entropy and regex",
 			description: "test entropy and regex",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_regex_entropy.json.got",
-				Config:   "../test_data/test_configs/regex_entropy.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_regex_entropy.json.got",
+				Config:       "../test_data/test_configs/regex_entropy.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_regex_entropy.json",
 			wantPath: "../test_data/test_regex_entropy.json",
 		},
 		},
 		{
 		{
 			description: "test local repo four entropy alternative config",
 			description: "test local repo four entropy alternative config",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath:   "../test_data/test_repos/test_repo_4",
-				Report:     "../test_data/test_local_repo_four_alt_config_entropy.json.got",
-				RepoConfig: true,
+				RepoPath:     "../test_data/test_repos/test_repo_4",
+				Report:       "../test_data/test_local_repo_four_alt_config_entropy.json.got",
+				RepoConfig:   true,
+				ReportFormat: "json",
 			},
 			},
 			wantPath: "../test_data/test_local_repo_four_alt_config_entropy.json",
 			wantPath: "../test_data/test_local_repo_four_alt_config_entropy.json",
 		},
 		},
 		{
 		{
 			description: "test local repo four entropy alternative config",
 			description: "test local repo four entropy alternative config",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath: "../test_data/test_repos/test_repo_1",
-				Report:   "../test_data/test_regex_whitelist.json.got",
-				Config:   "../test_data/test_configs/aws_key_aws_whitelisted.toml",
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_regex_whitelist.json.got",
+				Config:       "../test_data/test_configs/aws_key_aws_whitelisted.toml",
+				ReportFormat: "json",
 			},
 			},
 			wantEmpty: true,
 			wantEmpty: true,
 		},
 		},
@@ -222,9 +238,10 @@ func TestAuditUncommited(t *testing.T) {
 		{
 		{
 			description: "test audit local one leak",
 			description: "test audit local one leak",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath:   "../test_data/test_repos/test_repo_1",
-				Report:     "../test_data/test_local_repo_one_aws_leak_uncommitted.json.got",
-				Uncommited: true,
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Report:       "../test_data/test_local_repo_one_aws_leak_uncommitted.json.got",
+				Uncommited:   true,
+				ReportFormat: "json",
 			},
 			},
 			wantPath:     "../test_data/test_local_repo_one_aws_leak_uncommitted.json",
 			wantPath:     "../test_data/test_local_repo_one_aws_leak_uncommitted.json",
 			fileToChange: "server.test.py",
 			fileToChange: "server.test.py",
@@ -233,8 +250,9 @@ func TestAuditUncommited(t *testing.T) {
 		{
 		{
 			description: "test audit local no leak",
 			description: "test audit local no leak",
 			opts: options.Options{
 			opts: options.Options{
-				RepoPath:   "../test_data/test_repos/test_repo_1",
-				Uncommited: true,
+				RepoPath:     "../test_data/test_repos/test_repo_1",
+				Uncommited:   true,
+				ReportFormat: "json",
 			},
 			},
 			wantEmpty:    true,
 			wantEmpty:    true,
 			fileToChange: "server.test.py",
 			fileToChange: "server.test.py",