// realMain is the real main function, which returns the value to pass to // os.Exit(). We have to do this so we can use defer. func realMain(m *testing.M) int { flag.Parse() defer glog.Flush() // Generate certificates in a temporary directory. tmpDir, err := ioutil.TempDir("", "dnss_test:") if err != nil { fmt.Printf("Failed to create temp dir: %v\n", tmpDir) return 1 } defer os.RemoveAll(tmpDir) err = generateCert(tmpDir) if err != nil { fmt.Printf("Failed to generate cert for testing: %v\n", err) return 1 } // DNS to GRPC server. gr := dnstox.NewGRPCResolver(grpcToDnsAddr, tmpDir+"/cert.pem") cr := dnstox.NewCachingResolver(gr) dtg := dnstox.New(dnsToGrpcAddr, cr, "") go dtg.ListenAndServe() // GRPC to DNS server. gtd := &grpctodns.Server{ Addr: grpcToDnsAddr, Upstream: dnsSrvAddr, CertFile: tmpDir + "/cert.pem", KeyFile: tmpDir + "/key.pem", } go gtd.ListenAndServe() // DNS test server. dnsSrv := dnsServer{ Addr: dnsSrvAddr, } go dnsSrv.ListenAndServe() // Wait for the servers to start up. err = util.WaitForDNSServer(dnsToGrpcAddr) if err != nil { fmt.Printf("Error waiting for the test servers to start: %v\n", err) fmt.Printf("Check the INFO logs for more details\n") return 1 } return m.Run() }
// realMain is the real main function, which returns the value to pass to // os.Exit(). We have to do this so we can use defer. func realMain(m *testing.M) int { flag.Parse() defer glog.Flush() DNSAddr = util.GetFreePort() // Test http server. httpsrv := httptest.NewServer(http.HandlerFunc(DNSHandler)) // DNS to HTTPS server. r := dnstox.NewHTTPSResolver(httpsrv.URL, "") dth := dnstox.New(DNSAddr, r, "") go dth.ListenAndServe() // Wait for the servers to start up. err := util.WaitForDNSServer(DNSAddr) if err != nil { fmt.Printf("Error waiting for the test servers to start: %v\n", err) fmt.Printf("Check the INFO logs for more details\n") return 1 } return m.Run() }