Ejemplo n.º 1
0
func TestMustNewPackageFromImportPath(ot *testing.T) {
	pkg := kmgGoSource.MustNewPackageFromImportPath("github.com/bronze1man/kmg/kmgReflect")
	kmgTest.Equal(pkg.PkgPath(), "github.com/bronze1man/kmg/kmgReflect")

	pkg = kmgGoSource.MustNewPackageFromImportPath("go/doc")
	kmgTest.Equal(pkg.PkgPath(), "go/doc")
}
Ejemplo n.º 2
0
func TestParseImportPath(ot *testing.T) {
	importPathList := parseImportPath("<nil>", []byte(`
/*
	import (
		"github.com/bronze1man/kmg/kmgView/webResource/bootstrap"
		"boostrap"
	)
*/
`))
	kmgTest.Equal(importPathList, []string{
		"github.com/bronze1man/kmg/kmgView/webResource/bootstrap",
		"boostrap",
	})

	importPathList = parseImportPath("<nil>", []byte(`
/*
*/
`))
	kmgTest.Equal(importPathList, nil)

	importPathList = parseImportPath("<nil>", []byte(`
/*
*/
/*
	import (
		"github.com/bronze1man/kmg/kmgView/webResource/bootstrap"
		"boostrap"
	)
*/
`))
	kmgTest.Equal(importPathList, nil)
}
Ejemplo n.º 3
0
func TestPeriodList(ot *testing.T) {
	itemList := ScratchItemList3{
		[]int{1, 2},
		[]int{2, 3},
		[]int{3, 4},
	}
	periodList := PeriodList{
		{
			Period:      Period{Start: MustFromMysqlFormat("2001-01-00 23:30:00"), End: MustFromMysqlFormat("2001-01-01 23:30:00")},
			OriginIndex: 0,
		},
		{
			Period:      Period{Start: MustFromMysqlFormat("2001-01-03 23:30:00"), End: MustFromMysqlFormat("2001-01-04 23:30:00")},
			OriginIndex: 1,
		},
		{
			Period:      Period{Start: MustFromMysqlFormat("2001-01-02 23:30:00"), End: MustFromMysqlFormat("2001-01-03 23:30:00")},
			OriginIndex: 2,
		},
	}
	periodList.Sort()
	i, exist := periodList.SelectFromTime(MustFromMysqlFormat("2001-01-01 23:00:00"))
	kmgTest.Equal(exist, true)
	kmgTest.Equal(itemList[i], []int{1, 2})
	i, exist = periodList.SelectFromTime(MustFromMysqlFormat("2001-01-03 23:00:00"))
	kmgTest.Equal(exist, true)
	kmgTest.Equal(itemList[i], []int{3, 4})
}
Ejemplo n.º 4
0
func TestFileChangeCacheOneFile(t *testing.T) {
	//可以递归 遍历文件
	//缓存数据文件不存在,没有问题
	//指定的文件不存在,也没有问题
	callLog := make([]string, 32)
	//指定的文件不存在
	kmgFile.MustDeleteFile(getFileChangeCachePath("test_file_change_cache"))
	kmgFile.MustDeleteFile("testFile/notExist")

	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/notExist",
	}, func() {
		callLog[1] = "notExist"
		kmgFile.MustWriteFileWithMkdir("testFile/notExist", []byte("1"))
	})
	kmgTest.Equal(callLog[1], "notExist")

	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/notExist",
	}, func() {
		callLog[2] = "notExist"
	})
	kmgTest.Equal(callLog[2], "")

	time.Sleep(time.Second * 1)

	kmgFile.MustWriteFile("testFile/notExist", []byte("2"))
	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/notExist",
	}, func() {
		callLog[3] = "notExist"
	})
	kmgTest.Equal(callLog[3], "notExist")
}
Ejemplo n.º 5
0
func TestKmgPageWithDb(ot *testing.T) {
	setupDb()
	kmgSql.MustExec("DROP TABLE IF EXISTS `kmgSql_test_table`")
	kmgSql.MustExec("CREATE TABLE `kmgSql_test_table` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Info` varchar(255) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")
	kmgSql.MustSetTableDataYaml(`
kmgSql_test_table:
   - Id: 1
   - Id: 2
   - Id: 3
   - Id: 4
`)
	pager := kmgPage.CreateFromSelectCommand(kmgPage.CreateFromSelectCommandRequest{
		Select:      MysqlAst.NewSelectCommand().From("kmgSql_test_table"),
		Url:         "/?n=a",
		ItemPerPage: 2,
		CurrentPage: 1,
	})
	kmgTest.Equal(len(pager.Data), 2)

	pager = kmgPage.CreateFromSelectCommand(kmgPage.CreateFromSelectCommandRequest{
		Select: MysqlAst.NewSelectCommand().From("kmgSql_test_table"),
		Url:    "/?n=a",
	})
	kmgTest.Equal(len(pager.Data), 4)
}
Ejemplo n.º 6
0
func TestMustTlsTestListen(ot *testing.T) {
	listener := kmgCrypto.MustTlsTestListen(":0")
	defer listener.Close()
	listenAddr := kmgNet.MustGetLocalAddrFromListener(listener)
	waitAcceptChan := make(chan int)
	go func() {
		defer func() { waitAcceptChan <- 1 }()
		conn, err := listener.Accept()
		kmgTest.Equal(err, nil)
		defer conn.Close()
		//此处开始检测两条连接是否连在了一起
		result, err := ioutil.ReadAll(conn)
		kmgTest.Equal(err, nil)
		kmgTest.Ok(bytes.Equal(result, []byte(`hello world`)))
	}()
	conn, err := tls.Dial("tcp", listenAddr, &tls.Config{
		InsecureSkipVerify: true,
	})
	kmgTest.Equal(err, nil)
	defer conn.Close()
	_, err = conn.Write([]byte(`hello world`))
	kmgTest.Equal(err, nil)
	conn.Close()
	<-waitAcceptChan
}
Ejemplo n.º 7
0
func TestDurationFormat(ot *testing.T) {
	kmgTest.Equal(DurationFormat(time.Second), "1s")
	kmgTest.Equal(DurationFormat(1000*time.Second), "16m40s")
	kmgTest.Equal(DurationFormat(12345*time.Millisecond), "12.34s")
	kmgTest.Equal(DurationFormat(1234*time.Microsecond), "1.23ms")
	kmgTest.Equal(DurationFormat(1234*time.Nanosecond), "1.23µs")
}
Ejemplo n.º 8
0
func TestGetPeriodFromSortedList(ot *testing.T) {
	SortedList := []Period{
		{
			Start: MustFromMysqlFormat("2001-01-01 00:00:00"),
			End:   MustFromMysqlFormat("2001-01-01 01:00:00"),
		},
		{
			Start: MustFromMysqlFormat("2001-01-01 02:00:00"),
			End:   MustFromMysqlFormat("2001-01-01 03:00:00"),
		},
		{
			Start: MustFromMysqlFormat("2001-01-01 03:00:00"),
			End:   MustFromMysqlFormat("2001-01-01 04:00:00"),
		},
	}
	for _, testcase := range []struct {
		t  time.Time
		i  int
		ok bool
	}{
		{MustFromMysqlFormat("2001-01-00 23:30:00"), 0, false},
		{MustFromMysqlFormat("2001-01-01 00:30:00"), 0, true},
		{MustFromMysqlFormat("2001-01-01 03:00:00"), 2, true},
		{MustFromMysqlFormat("2001-01-01 04:30:00"), 0, false},
	} {
		i, ok := GetPeriodFromSortedList(testcase.t, SortedList)
		kmgTest.Equal(i, testcase.i)
		kmgTest.Equal(ok, testcase.ok)
	}
}
Ejemplo n.º 9
0
func benchmarkScanCallback() {
	N := 1000 * 100
	MustFlushDbV2()
	t := time.Now()
	pairList := make([]KeyValuePair, N)
	for i := 0; i < N; i++ {
		pairList[i].Key = "test_" + strconv.Itoa(i)
		pairList[i].Value = "abc"
	}
	MustMSet(pairList)
	fmt.Println(time.Since(t)) //386.265848ms
	t = time.Now()
	num := 0
	err := ScanCallback("*", func(key string) error {
		num++
		return nil
	}) //169.983354ms
	fmt.Println(time.Since(t))
	kmgTest.Equal(err, nil)
	kmgTest.Equal(num, N)
	t = time.Now()
	sList, err := Keys("*") //138.565292ms
	fmt.Println(time.Since(t))
	kmgTest.Equal(err, nil)
	kmgTest.Equal(len(sList), N)
	MustFlushDbV2()
}
Ejemplo n.º 10
0
func TestTap(ot *testing.T) {
	tap, err := NewTap("")
	if os.IsPermission(err) {
		ot.Skip("you need root permission to run this test.")
		return
	}
	kmgTest.Equal(err, nil)
	defer tap.Close()
	kmgTest.Equal(tap.GetDeviceType(), DeviceTypeTap)

	err = kmgCmd.CmdString("ifconfig " + tap.Name() + " 10.209.34.1 up").GetExecCmd().Run()
	kmgTest.Equal(err, nil)
	/*
		cmd := kmgCmd.NewOsStdioCmdString("ping 10.0.0.2")
		err = cmd.Start()
		t.Equal(err, nil)
		defer cmd.Process.Kill()

		buf := make([]byte, 4096)
		n, err := tun.Read(buf)
		t.Equal(err, nil)
		t.Ok(n > 0)

		tun2, err := NewTap("")
		t.Equal(err, nil)
		defer tun2.Close()
	*/
}
Ejemplo n.º 11
0
func TestAuthPap(ot *testing.T) {
	//AccessRequest
	inBytes := []byte{0x1, 0xef, 0x0, 0x8e, 0x94, 0xb, 0x18, 0xaf, 0xa, 0xb6, 0x12, 0xf5, 0x24, 0x4, 0x94, 0xbe, 0x18, 0xbc, 0x7, 0x4d,
		0x1, 0x4, 0x72, 0x48, 0x3d, 0x6, 0x0, 0x0, 0x0, 0x5, 0x6, 0x6, 0x0, 0x0, 0x0, 0x2, 0x5, 0x6, 0x0, 0x0, 0x0, 0x10, 0x57,
		0xf, 0x69, 0x6f, 0x73, 0x5f, 0x78, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x70, 0x73, 0x6b, 0x4, 0x6, 0xa, 0x1, 0x1, 0x5, 0x1e,
		0xf, 0x31, 0x30, 0x2e, 0x31, 0x2e, 0x31, 0x2e, 0x35, 0x5b, 0x35, 0x30, 0x30, 0x5d, 0x1f, 0x10, 0x31, 0x30, 0x2e, 0x31,
		0x2e, 0x31, 0x2e, 0x37, 0x30, 0x5b, 0x35, 0x30, 0x30, 0x5d, 0x20, 0xc, 0x73, 0x74, 0x72, 0x6f, 0x6e, 0x67, 0x53, 0x77,
		0x61, 0x6e, 0x2, 0x12, 0x8d, 0x7, 0xc2, 0xc0, 0xa4, 0x2, 0x2c, 0xed, 0x8e, 0x69, 0x5b, 0x9e, 0x25, 0x77, 0xe5, 0xd, 0x50,
		0x12, 0x39, 0x5c, 0xaa, 0x3e, 0x6d, 0x23, 0xea, 0xb5, 0x86, 0xc1, 0x3, 0x2d, 0x9d, 0x5c, 0x19, 0xca}
	server := server{
		handler: Handler{
			Auth: func(username string) (password string, exist bool) {
				if username != "rH" {
					panic(`username!="rH"`)
				}
				return "O6", true
			},
		},
	}
	inPac, err := DecodeRequestPacket([]byte("sEcReT"), inBytes)
	kmgTest.Equal(inPac.GetPassword(), "O6")
	kmgTest.Ok(err == nil)
	outPac := server.PacketHandler(inPac)
	kmgTest.Equal(outPac.Code, CodeAccessAccept)
}
Ejemplo n.º 12
0
func TestRsaOpensslVerify(ot *testing.T) {
	var err error
	private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hRSyDJWJVye0mPgbvVnx76en+K6LLzDaQH8yK
I/dbswSq65XFcIwIDAQAB
-----END PUBLIC KEY-----`)
	signed := kmgBase64.MustStdBase64DecodeStringToByte(`AqDW/m+aGn2kFo54Bt5XnXniBDtCxmPS6FMfHrLizh7d4jgnz4LbwBfRvXywI6HEKgr7Vk37duTM8P+XqmT+uQU2R1h4nRwOf2fCstXmgeD3qGk/XI+XMafgMkTnV/B9dOXpdUbxEpL1fDhmo7A6J0rcJotG7TP7i1zcvY4oiXk=`)
	msg := []byte("this is a test!")
	rsaKey, err := RsaParseOpensslPrivateKey(privateKey)
	s, err := RsaOpensslSign(rsaKey, crypto.SHA1, msg)
	kmgTest.Equal(err, nil)
	kmgTest.Equal(s, signed)

	rsapk, err := RsaParseOpensslPublicKey(publicKey)
	kmgTest.Equal(err, nil)
	err = RsaOpensslVerify(rsapk, crypto.SHA1, msg, signed)
	kmgTest.Equal(err, nil)
}
Ejemplo n.º 13
0
func TestUrlv(t *testing.T) {
	kmgTest.Equal(Urlv("abcd"), "abcd")
	kmgTest.Equal(Urlv("abcd哈"), "abcd%E5%93%88")
	kmgTest.Equal(Urlv("abcd "), "abcd%20")
	kmgTest.Equal(Urlv("abcd.abc"), "abcd.abc")

}
Ejemplo n.º 14
0
func TestFileChangeCacheOneDir(t *testing.T) {
	callLog := make([]string, 32)
	//递归可用
	kmgFile.MustDeleteFile(getFileChangeCachePath("test_file_change_cache"))
	kmgFile.MustMkdirAll("testFile/d1/d2")
	kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("1"))
	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/d1",
	}, func() {
		callLog[3] = "f3"
	})
	kmgTest.Equal(callLog[3], "f3")

	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/d1",
	}, func() {
		callLog[4] = "f3"
	})
	kmgTest.Equal(callLog[4], "")

	time.Sleep(time.Second * 1)
	kmgFile.MustWriteFile("testFile/d1/d2/f3", []byte("2"))
	MustFileChangeCache("test_file_change_cache", []string{
		"testFile/d1",
	}, func() {
		callLog[5] = "f3"
	})
	kmgTest.Equal(callLog[5], "f3")
}
Ejemplo n.º 15
0
func TestUnmarshalNaN(ot *testing.T) {
	value := map[string]interface{}{}
	err := Unmarshal([]byte("notanum: .NaN"), &value)
	kmgTest.Equal(err, nil)
	kmgTest.Equal(math.IsNaN(value["notanum"].(float64)), true)
	//c.Assert(err, IsNil)
	//c.Assert(math.IsNaN(value["notanum"].(float64)), Equals, true)
}
Ejemplo n.º 16
0
func TestMustFromMysqlFormatDefaultTZ(ot *testing.T) {
	t := MustFromMysqlFormatDefaultTZ("2001-01-01 00:00:00")
	kmgTest.Equal(t.Hour(), 0)
	kmgTest.Equal(t.Day(), 1)

	t = MustFromMysqlFormatDefaultTZ("0000-00-00 00:00:00")
	kmgTest.Equal(t.IsZero(), true)
}
Ejemplo n.º 17
0
func TestFixLocalTimeToOffsetSpecifiedZoneTime(ot *testing.T) {
	otherZoneTime := FixLocalTimeToOffsetSpecifiedZoneTime(3600, localTime)
	kmgTest.Equal(otherZoneTime, "2015-11-12 07:15:55")
	otherZoneTime = FixLocalTimeToOffsetSpecifiedZoneTime(7200, localTime)
	kmgTest.Equal(otherZoneTime, "2015-11-12 08:15:55")
	otherZoneTime = FixLocalTimeToOffsetSpecifiedZoneTime(-18000, localTime)
	kmgTest.Equal(otherZoneTime, "2015-11-12 01:15:55")
}
Ejemplo n.º 18
0
func TestHash(ot *testing.T) {
	etag, err := ComputeHashFromFile("testFile/1.txt")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(etag, "FqmZPjZHBoFquj4lcXhQwmyc0Nid")

	etag = ComputeHashFromBytes([]byte("abc"))
	kmgTest.Equal(etag, "FqmZPjZHBoFquj4lcXhQwmyc0Nid")
}
Ejemplo n.º 19
0
func BenchmarkFastRandReader(ot *testing.B) {
	ot.StopTimer()
	buf := make([]byte, ot.N)
	ot.SetBytes(int64(1))
	ot.StartTimer()
	n, err := FastRandReader.Read(buf)
	kmgTest.Equal(n, ot.N)
	kmgTest.Equal(err, nil)
}
Ejemplo n.º 20
0
func TestKmgCipherV2(ot *testing.T) {
	//加密数据,可以正确解密测试
	for _, origin := range [][]byte{
		[]byte(""),
		[]byte("1"),
		[]byte("12"),
		[]byte("123"),
		[]byte("1234"),
		[]byte("12345"),
		[]byte("123456"),
		[]byte("1234567"),
		[]byte("12345678"),
		[]byte("123456789"),
		[]byte("1234567890"),
		[]byte("123456789012345"),
		[]byte("1234567890123456"),
		[]byte("12345678901234567"),
	} {
		ob := EncryptV2([]byte("1"), origin)
		ret, err := DecryptV2([]byte("1"), ob)
		kmgTest.Equal(err, nil)
		kmgTest.Equal(ret, origin)
	}
	//任意数据传入解密不会挂掉,并且会报错
	for _, origin := range [][]byte{
		[]byte(""),
		[]byte("1"),
		[]byte("12"),
		[]byte("123"),
		[]byte("1234"),
		[]byte("12345"),
		[]byte("123456"),
		[]byte("1234567"),
		[]byte("12345678"),
		[]byte("123456789"),
		[]byte("1234567890"),
		[]byte("123456789012345"),
		[]byte("1234567890123456"),
		[]byte("12345678901234567"),
	} {
		_, err := Decrypt([]byte("1"), origin)
		kmgTest.Ok(err != nil)
	}
	origin := []byte("1234567890123456712345678901234567")
	//多次加密得到不同的结果 (随机化iv)
	kmgTest.Ok(!bytes.Equal(EncryptV2([]byte("1"), origin), EncryptV2([]byte("1"), origin)))
	//修改任何一个字节都会报错 (hash)

	ob := EncryptV2([]byte("1"), origin)
	for i := 0; i < len(ob); i++ {
		newOb := make([]byte, len(ob))
		newOb[i] = -newOb[i]
		_, err := DecryptV2([]byte("1"), newOb)
		kmgTest.Ok(err != nil)
	}
}
Ejemplo n.º 21
0
func TestCpu(t *testing.T) {
	out := `Linux 3.13.0-55-generic (DEV-BCE) 	07/15/2015 	_x86_64_	(2 CPU)

09:16:45 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:16:45 AM  all    0.45    0.01    0.17    0.27    0.00    0.00    0.00    0.00    0.00   99.10
`
	used, count := cpu(out)
	kmgTest.Equal(used, 0.009)
	kmgTest.Equal(count, 2)
}
Ejemplo n.º 22
0
func TestGenerated(ot *testing.T) {
	psk := kmgCrypto.Get32PskFromString("abc")
	closer := ListenAndServe_Demo(":34895", &Demo{}, psk)
	defer closer()
	client := NewClient_Demo("http://127.0.0.1:34895/f", psk)
	info, err := client.PostScoreInt("LbId", 1)
	kmgTest.Equal(err, nil)
	kmgTest.Equal(info, "LbId")

	info, err = client.PostScoreInt("LbId", 2)
	kmgTest.Equal(info, "")
	kmgTest.Ok(err != nil, err)
	kmgTest.Equal(err.Error(), "Score!=1")

	info, err = client.DemoFunc8(DemoRequest{}, &DemoRequest{}, 1)
	kmgTest.Equal(info, "info1")

	info, err = client.DemoFunc8(DemoRequest{}, &DemoRequest{}, 2)
	kmgTest.Equal(info, "info")

	inT := kmgTime.MustParseAutoInDefault("2001-01-01 01:01:01")
	outT, err := client.DemoTime(inT)
	kmgTest.Equal(err, nil)
	kmgTest.Ok(outT.Equal(kmgTime.MustParseAutoInDefault("2001-01-01T02:01:01.001000001+08:00")), outT)

	ip, err := client.DemoClientIp()
	kmgTest.Equal(err, nil)
	kmgTest.Equal(ip, "127.0.0.1")
}
Ejemplo n.º 23
0
func TestStringType(ot *testing.T) {
	var data *string
	data = new(string)
	m, err := NewContext(data)
	kmgTest.Equal(err, nil)

	err = m.SaveByPath(Path{"ptr"}, "123")
	kmgTest.Equal(err, nil)
	kmgTest.Ok(data != nil)
	kmgTest.Equal(*data, "123")
}
Ejemplo n.º 24
0
func TestMustTlsTestListenHttps(ot *testing.T) {
	listener := kmgCrypto.MustTlsTestListen(":0")
	defer listener.Close()
	go http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("hello world"))
	}))
	c := kmgHttp.NewHttpsCertNotCheckClient()
	resp, err := c.Get("https://" + kmgNet.MustGetLocalAddrFromListener(listener))
	kmgTest.Equal(err, nil)
	kmgTest.Equal(resp.StatusCode, 200)
}
Ejemplo n.º 25
0
func TestGetAllFileAndDirectoryStat(t *testing.T) {
	MustMkdirAll("testFile/d1/d2")
	MustWriteFile("testFile/d1/d2/f3", []byte("1"))
	out, err := GetAllFileAndDirectoryStat("testFile")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(len(out), 4)

	out, err = GetAllFileAndDirectoryStat("testFile/d1/d2/f3")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(len(out), 1)
}
Ejemplo n.º 26
0
func TestMustIsFileInIndex(t *testing.T) {
	GitTestCb(func() {
		kmgCmd.MustRun("git init")
		kmgFile.MustWriteFile("1.txt", []byte("1"))
		kmgFile.MustWriteFile("2.txt", []byte("1"))
		kmgCmd.MustRun("git add 1.txt")
		repo := MustGetRepositoryFromPath(".")
		kmgTest.Equal(repo.MustIsFileInIndex("1.txt"), true)
		kmgTest.Equal(repo.MustIsFileInIndex("2.txt"), false)
	})
}
Ejemplo n.º 27
0
func TestZipUncompressFromBytesToDir(ot *testing.T) {
	kmgFile.MustDeleteFileOrDirectory("testfile")

	contentB := []byte{0x50, 0x4b, 0x3, 0x4, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x79, 0xb1, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x3, 0x4, 0x14, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x50, 0x4b, 0x3, 0x4, 0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb3, 0xa5, 0x46, 0x0, 0x0, 0x0, 0x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 0x0, 0x3, 0x0, 0x3, 0x0, 0xa6, 0x0, 0x0, 0x0, 0x76, 0x0, 0x0, 0x0, 0x0, 0x0}
	err := ZipUncompressFromBytesToDir(contentB, "testfile", "")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(kmgFile.MustReadFileAll("testfile/testfile/1.txt"), []byte(""))

	err = ZipUncompressFromBytesToDir(contentB, "testfile", "testfile")
	kmgTest.Equal(err, nil)
	kmgTest.Equal(kmgFile.MustReadFileAll("testfile/1.txt"), []byte(""))
}
Ejemplo n.º 28
0
func TestStructType(ot *testing.T) {
	data := &struct {
		A string
	}{}
	m, err := NewContext(data)
	kmgTest.Equal(err, nil)

	err = m.SaveByPath(Path{"ptr", "A"}, "123")
	kmgTest.Equal(err, nil)
	kmgTest.Ok(data != nil)
	kmgTest.Equal(data.A, "123")
}
Ejemplo n.º 29
0
func TestExtractProcessList(t *testing.T) {
	pList := Extract(` 5393 /usr/bin/InlProxy vpnAccount -redisAddr=127.0.0.1:30001
 5424 /usr/bin/xasdf -block
 5455 /usr/bin/asdfkja;sdflk -nl asdfadsf;ak
 5590 /usr/bin/abc
 6625 InlProxy
 7254 InlProxy abc
27939 /usr/bin/InlProxy`)
	kmgTest.Equal(len(pList), 7)
	kmgTest.Equal(pList[1].Id, 5424)
	kmgTest.Equal(pList[5].Command, "InlProxy abc")
}
Ejemplo n.º 30
0
func TestGenerated(ot *testing.T) {
	closer := ListenAndServe_Demo(":34895", &Demo{})
	defer closer()
	client := NewClient_Demo("http://127.0.0.1:34895/f")
	info, err := client.PostScoreInt("LbId", 1)
	kmgTest.Equal(err, nil)
	kmgTest.Equal(info, "LbId")

	info, err = client.PostScoreInt("LbId", 2)
	kmgTest.Equal(err.Error(), "Score!=1")
	kmgTest.Equal(info, "")
}