You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
package goping
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/fatih/color"
|
|
"os"
|
|
"os/signal"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPing2(t *testing.T) {
|
|
Ping("www.baidu1.com", 48)
|
|
}
|
|
func TestColor(tt *testing.T) {
|
|
// Create SprintXxx functions to mix strings with other non-colorized strings:
|
|
yellow := color.New(color.FgYellow).SprintFunc()
|
|
red := color.New(color.FgRed).SprintFunc()
|
|
fmt.Printf("This is a %s and this is %s.\n", yellow("warning"), red("error"))
|
|
|
|
info := color.New(color.FgWhite, color.BgGreen).SprintFunc()
|
|
fmt.Printf("This %s rocks!\n", info("package"))
|
|
|
|
// Use helper functions
|
|
fmt.Println("This", color.RedString("warning"), "should be not neglected.")
|
|
fmt.Printf("%v %v\n", color.GreenString("Info:"), "an important message.")
|
|
|
|
// Windows supported too! Just don't forget to change the output to color.Output
|
|
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS"))
|
|
|
|
}
|
|
func TestSign(tt *testing.T) {
|
|
c := make(chan os.Signal, 1)
|
|
for {
|
|
select {
|
|
case s := <-c:
|
|
signal.Notify(c, os.Interrupt, os.Kill)
|
|
fmt.Println("Got signal:", s)
|
|
os.Exit(0)
|
|
default:
|
|
fmt.Println("okok")
|
|
time.Sleep(time.Second * 1)
|
|
}
|
|
}
|
|
}
|
|
func TestPing(tt *testing.T) {
|
|
//if len(os.Args) < 3 {
|
|
// fmt.Printf("Param domain |data package Sizeof|trace times\n Ex: ./Ping www.so.com 100 4\n")
|
|
// os.Exit(1)
|
|
//}
|
|
//PS, err := strconv.Atoi(os.Args[2])
|
|
//if err != nil {
|
|
// fmt.Println("you need input correct PackageSizeof(complete int)")
|
|
// os.Exit(1)
|
|
//}
|
|
//Count, err := strconv.Atoi(os.Args[3])
|
|
//if err != nil {
|
|
// fmt.Println("you need input correct Counts")
|
|
// os.Exit(1)
|
|
//}
|
|
Ping("www.baidu.com", 48)
|
|
//Ping("www.baidu.com", 48, 5)
|
|
}
|