• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang snmpgo.Variable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/k-sone/snmpgo.Variable的典型用法代码示例。如果您正苦于以下问题:Golang Variable类的具体用法?Golang Variable怎么用?Golang Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Variable类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestNewOid

func TestNewOid(t *testing.T) {
	expStr := ".1.3.6.1.2.1.1.1.0"
	var v snmpgo.Variable

	v, err := snmpgo.NewOid(expStr)
	if err != nil {
		t.Errorf("NewOid : %v", err)
	}

	if expStr[1:] != v.String() {
		t.Errorf("String() - expected [%s], actual[%s]", expStr[1:], v.String())
	}

	var s []string
	for i := 0; i <= 128; i++ {
		s = append(s, strconv.Itoa(i))
	}
	expStr = strings.Join(s, ".")
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid sub-identifiers size")
	}

	expStr = "1.3.6.1.2.1.-1.0"
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid sub-identifier range")
	}

	expStr = "1.3.6.1.2.1.4294967296.0"
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid sub-identifier range")
	}

	expStr = "3.3.6.1.2.1.1.1.0"
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid first sub-identifier range")
	}

	expStr = "1"
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid sub-identifiers size")
	}

	expStr = "1.40.6.1.2.1.1.1.0"
	v, err = snmpgo.NewOid(expStr)
	if err == nil {
		t.Errorf("NewOid first sub-identifier range")
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:53,代码来源:variables_test.go


示例2: TestOid

func TestOid(t *testing.T) {
	expStr := "1.3.6.1.2.1.1.1.0"
	expBuf := []byte{0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00}
	var v snmpgo.Variable

	v, err := snmpgo.NewOid(expStr)
	if err != nil {
		t.Errorf("NewOid : %v", err)
	}

	_, err = v.BigInt()
	if err == nil {
		t.Errorf("Failed to call BigInt()")
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual[%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.Oid
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:46,代码来源:variables_test.go


示例3: TestCounter64

func TestCounter64(t *testing.T) {
	expInt := uint64(18446744073709551615)
	expStr := "18446744073709551615"
	expBuf := []byte{0x46, 0x09, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
	var v snmpgo.Variable = snmpgo.NewCounter64(expInt)

	big, err := v.BigInt()
	if err != nil {
		t.Errorf("Failed to call BigInt(): %v", err)
	}
	if expInt != big.Uint64() {
		t.Errorf("BigInt() - expected [%d], actual [%d]", expInt, big.Int64())
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual [%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.Counter64
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:45,代码来源:variables_test.go


示例4: TestTimeTicks

func TestTimeTicks(t *testing.T) {
	expInt := int64(4294967295)
	expStr := "4294967295"
	expBuf := []byte{0x43, 0x05, 0x00, 0xff, 0xff, 0xff, 0xff}
	var v snmpgo.Variable = snmpgo.NewTimeTicks(uint32(expInt))

	big, err := v.BigInt()
	if err != nil {
		t.Errorf("Failed to call BigInt(): %v", err)
	}
	if expInt != big.Int64() {
		t.Errorf("BigInt() - expected [%d], actual [%d]", expInt, big.Int64())
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual [%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.TimeTicks
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:45,代码来源:variables_test.go


示例5: TestIpaddress

func TestIpaddress(t *testing.T) {
	expStr := "192.168.1.1"
	expInt := int64(3232235777)
	expBuf := []byte{0x40, 0x04, 0xc0, 0xa8, 0x01, 0x01}
	var v snmpgo.Variable = snmpgo.NewIpaddress(0xc0, 0xa8, 0x01, 0x01)

	big, err := v.BigInt()
	if err != nil {
		t.Errorf("Failed to call BigInt(): %v", err)
	}
	if expInt != big.Int64() {
		t.Errorf("BigInt() - expected [%d], actual [%d]", expInt, big.Int64())
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual[%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.Ipaddress
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:45,代码来源:variables_test.go


示例6: TestEndOfMibView

func TestEndOfMibView(t *testing.T) {
	expStr := ""
	expBuf := []byte{0x82, 0x00}
	var v snmpgo.Variable = snmpgo.NewEndOfMibView()

	_, err := v.BigInt()
	if err == nil {
		t.Errorf("Failed to call BigInt()")
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual[%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.EndOfMibView
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:41,代码来源:variables_test.go


示例7: TestOpaque

func TestOpaque(t *testing.T) {
	expStr := "54:65:73:74"
	expBuf := []byte{0x44, 0x04, 0x54, 0x65, 0x73, 0x74}
	var v snmpgo.Variable = snmpgo.NewOpaque(expBuf[2:])

	_, err := v.BigInt()
	if err == nil {
		t.Errorf("Failed to call BigInt()")
	}

	if expStr != v.String() {
		t.Errorf("String() - expected [%s], actual[%s]", expStr, v.String())
	}

	buf, err := v.Marshal()
	if err != nil {
		t.Errorf("Marshal(): %v", err)
	}
	if !bytes.Equal(expBuf, buf) {
		t.Errorf("Marshal() - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(buf, " "))
	}

	var w snmpgo.Opaque
	rest, err := (&w).Unmarshal(buf)
	if len(rest) != 0 || err != nil {
		t.Errorf("Unmarshal() - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() - expected [%s], actual [%s]", expStr, w.String())
	}

	buf = append(buf, 0x00)
	rest, err = (&w).Unmarshal(buf)
	if len(rest) != 1 || err != nil {
		t.Errorf("Unmarshal() with rest - len[%d] err[%v]", len(rest), err)
	}
	if expStr != w.String() {
		t.Errorf("Unmarshal() with rest - expected [%s], actual [%s]", expStr, w.String())
	}
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:41,代码来源:variables_test.go



注:本文中的github.com/k-sone/snmpgo.Variable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pp.Println函数代码示例发布时间:2022-05-23
下一篇:
Golang models.User类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap