當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Server.SetCustomAttribute方法代碼示例

本文整理匯總了Golang中github.com/HewlettPackard/oneview-golang/icsp.Server.SetCustomAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.SetCustomAttribute方法的具體用法?Golang Server.SetCustomAttribute怎麽用?Golang Server.SetCustomAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/HewlettPackard/oneview-golang/icsp.Server的用法示例。


在下文中一共展示了Server.SetCustomAttribute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSetCustomAttribute

// TestSetCustomAttribute
func TestSetCustomAttribute(t *testing.T) {
	var (
		d *ICSPTest
		s icsp.Server
	)
	// unit test case
	d, _ = getTestDriverU()
	jsonServerData := d.Tc.GetTestData(d.Env, "ServerJSONString").(string)
	log.Debugf("jsonServerData => %s", jsonServerData)
	err := json.Unmarshal([]byte(jsonServerData), &s)
	assert.NoError(t, err, "Unmarshal Server threw error -> %s, %+v\n", err, jsonServerData)

	testKey1 := d.Tc.GetTestData(d.Env, "KeyTest1").(string)
	testScope1 := d.Tc.GetTestData(d.Env, "ScopeTest1").(string)
	expectsValue1 := d.Tc.GetExpectsData(d.Env, "ValueTest1").(string)

	// complete test case 1, simple read of custom attributes
	_, testValue1 := s.GetValueItem(testKey1, testScope1)
	assert.Equal(t, expectsValue1, testValue1.Value, "Should return testcase 1 simple read")
	// TODO: test case 2 , setting a value on existing attribute
	testKey2 := d.Tc.GetTestData(d.Env, "KeyTest2Existing").(string)
	testScope2 := d.Tc.GetTestData(d.Env, "ScopeTest2Existing").(string)
	testValueNew2 := d.Tc.GetTestData(d.Env, "ValueTest2ExistingNew").(string)
	expectsValueOld2 := d.Tc.GetExpectsData(d.Env, "ValueTestOld2").(string)
	expectsValueNew2 := d.Tc.GetExpectsData(d.Env, "ValueTestNew2").(string)

	_, testValue2 := s.GetValueItem(testKey2, testScope2)
	assert.Equal(t, expectsValueOld2, testValue2.Value, "Should return testcase 2 old setting existing attribute")

	s.SetCustomAttribute(testKey2, testScope2, testValueNew2)
	_, testValue2 = s.GetValueItem(testKey2, testScope2)
	assert.Equal(t, expectsValueNew2, testValue2.Value, "Should return testcase 2 new setting existing attribute")

	// TODO: test case 3, appending a new attribute
	testKey3 := d.Tc.GetTestData(d.Env, "KeyTest3New").(string)
	testScope3 := d.Tc.GetTestData(d.Env, "ScopeTest3New").(string)
	testValue3New := d.Tc.GetTestData(d.Env, "ValueTest3New").(string)
	expectsValue3 := d.Tc.GetExpectsData(d.Env, "ValueTest3").(string)

	i, _ := s.GetValueItem(testKey3, testScope3)
	assert.Equal(t, -1, i, "Should not find test case 3 value")

	s.SetCustomAttribute(testKey3, testScope3, testValue3New)
	_, testValue3 := s.GetValueItem(testKey3, testScope3)
	assert.Equal(t, expectsValue3, testValue3.Value, "Should return testcase 3 result")
}
開發者ID:HewlettPackard,項目名稱:oneview-golang,代碼行數:47,代碼來源:server_customattribute_test.go


注:本文中的github.com/HewlettPackard/oneview-golang/icsp.Server.SetCustomAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。