github.com/zmap/zlint@v1.1.0/integration/integration_test.go (about) 1 // +build integration 2 3 package integration 4 5 import ( 6 "flag" 7 "log" 8 "os" 9 "regexp" 10 "testing" 11 ) 12 13 var ( 14 // parallelism is a flag for controlling the number of linting Go routines 15 // used by TestCorpus. 16 parallelism = flag.Int("parallelism", 5, "number of linting Go routines to spawn") 17 // configFile is a flag for specifying the config file JSON. 18 configFile = flag.String("config", "./config.json", "integration test config file") 19 // forceDownload is a flag for forcing the download of data files even if they are in 20 // the cache dir already. 21 forceDownload = flag.Bool("forceDownload", false, "ignore cached data and force new download") 22 // saveExpected is a flag for controlling whether the expectedMap is saved to 23 // the configuration or not. 24 overwriteExpected = flag.Bool("overwriteExpected", false, "save test results as the new expected map in config file") 25 // fpSummarize is a flag for controlling whether a summary of the cert fingerprints 26 // with lint findings (e.g. one or more fatal, error, warning or info level 27 // findings) should be printed at the end of TestCorpus. Defaults to false 28 // because it is very spammy with a large corpus. 29 fpSummarize = flag.Bool("fingerprintSummary", false, "print summary of all certificate fingerprints with lint findings") 30 // lintSummarize is a flag for controlling whether a summary of result types 31 // by lint name is printed at the end of TestCorpus. Defaults to false because 32 // it is very spammy with a large corpus. 33 lintSummarize = flag.Bool("lintSummary", false, "print summary of result type counts by lint name") 34 // fpFilterString is a flag for controlling which certificate fingerprints are run 35 // through the lints. 36 fpFilterString = flag.String("fingerprintFilter", "", "if not-empty only certificate fingerprints that match the provided regexp will be run") 37 // lintFilterString is a flag for controlling which lints are run against the test 38 // corpus. 39 lintFilterString = flag.String("lintFilter", "", "if not-empty only lints with a name that match the provided regexp will be run") 40 // outputTick is a flag for controlling the number of certificates that are 41 // linted before a '.' is printed in the console. This controls the mechanism 42 // used to keep Travis from thinking the job is dead because there hasn't been 43 // output. 44 outputTick = flag.Int("outputTick", 1000, 45 "number of certificates to lint before printing a '.' marker in the output") 46 ) 47 48 var ( 49 // config is a global var for the integration test configuration. 50 conf *config 51 52 // fpFilter and lintFilter are regexps for filtering certificate fingerprints 53 // to be linted and lints to be run. 54 fpFilter, lintFilter *regexp.Regexp 55 ) 56 57 // TestMain loads the integration test config, validates it, and prepares the 58 // cache (downloading configured CSV data files if needed), and then runs all tests. 59 func TestMain(m *testing.M) { 60 flag.Parse() 61 62 if *fpFilterString != "" { 63 filter, err := regexp.Compile(*fpFilterString) 64 if err != nil { 65 log.Fatalf("error compiling -fingerprintFilter regexp %q: %v", *fpFilterString, err) 66 } 67 fpFilter = filter 68 } 69 70 if *lintFilterString != "" { 71 filter, err := regexp.Compile(*lintFilterString) 72 if err != nil { 73 log.Fatalf("error compiling -lintFilter regexp %q: %v", *lintFilterString, err) 74 } 75 lintFilter = filter 76 } 77 78 // Load and validate configuration 79 c, err := loadConfig(*configFile) 80 if err != nil { 81 log.Fatalf("error loading config file %q: %v", *configFile, err) 82 } 83 if err := c.Valid(); err != nil { 84 log.Fatalf("error processing config file %q: %v", *configFile, err) 85 } 86 87 // Prepare cache, downloading data files if required (or if forced by user 88 // request with forceDownload) 89 if err := c.PrepareCache(*forceDownload); err != nil { 90 log.Fatalf("error preparing cache: %v\n", err) 91 } 92 // Save the config to a global accessible to tests. 93 conf = c 94 95 // Run all tests. 96 os.Exit(m.Run()) 97 }