asset_json_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package opencost
  2. import (
  3. "github.com/opencost/opencost/core/pkg/util/json"
  4. "testing"
  5. "time"
  6. )
  7. var s = time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC)
  8. var e = start1.Add(day)
  9. var unmarshalWindow = NewWindow(&s, &e)
  10. func TestAny_Unmarshal(t *testing.T) {
  11. any1 := NewAsset(*unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  12. any1.SetProperties(&AssetProperties{
  13. Name: "any1",
  14. Cluster: "cluster1",
  15. ProviderID: "any1",
  16. })
  17. any1.Cost = 9.0
  18. any1.SetAdjustment(1.0)
  19. bytes, _ := json.Marshal(any1)
  20. var testany Any
  21. any2 := &testany
  22. err := json.Unmarshal(bytes, any2)
  23. // Check if unmarshal was successful
  24. if err != nil {
  25. t.Fatalf("Any Unmarshal: unexpected error: %s", err)
  26. }
  27. // Check if all fields in initial Any equal those in Any from unmarshal
  28. if !any1.Properties.Equal(any2.Properties) {
  29. t.Fatalf("Any Unmarshal: properties mutated in unmarshal")
  30. }
  31. if !any1.Labels.Equal(any2.Labels) {
  32. t.Fatalf("Any Unmarshal: labels mutated in unmarshal")
  33. }
  34. if !any1.Window.Equal(any2.Window) {
  35. t.Fatalf("Any Unmarshal: window mutated in unmarshal")
  36. }
  37. if !any1.Start.Equal(any2.Start) {
  38. t.Fatalf("Any Unmarshal: start mutated in unmarshal")
  39. }
  40. if !any1.End.Equal(any2.End) {
  41. t.Fatalf("Any Unmarshal: end mutated in unmarshal")
  42. }
  43. if any1.Adjustment != any2.Adjustment {
  44. t.Fatalf("Any Unmarshal: adjustment mutated in unmarshal")
  45. }
  46. if any1.Cost != any2.Cost {
  47. t.Fatalf("Any Unmarshal: cost mutated in unmarshal")
  48. }
  49. // As a final check, make sure the above checks out
  50. if !any1.Equal(any2) {
  51. t.Fatalf("Any Unmarshal: Any mutated in unmarshal")
  52. }
  53. }
  54. func TestCloud_Unmarshal(t *testing.T) {
  55. cloud1 := NewCloud("Compute", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  56. cloud1.SetLabels(map[string]string{
  57. "namespace": "namespace1",
  58. "env": "env1",
  59. "product": "product1",
  60. })
  61. cloud1.Cost = 10.00
  62. cloud1.Credit = -1.0
  63. bytes, _ := json.Marshal(cloud1)
  64. var testcloud Cloud
  65. cloud2 := &testcloud
  66. err := json.Unmarshal(bytes, cloud2)
  67. // Check if unmarshal was successful
  68. if err != nil {
  69. t.Fatalf("Cloud Unmarshal: unexpected error: %s", err)
  70. }
  71. // Check if all fields in initial Cloud equal those in Cloud from unmarshal
  72. if !cloud1.Properties.Equal(cloud2.Properties) {
  73. t.Fatalf("Cloud Unmarshal: properties mutated in unmarshal")
  74. }
  75. if !cloud1.Labels.Equal(cloud2.Labels) {
  76. t.Fatalf("Cloud Unmarshal: labels mutated in unmarshal")
  77. }
  78. if !cloud1.Window.Equal(cloud2.Window) {
  79. t.Fatalf("Cloud Unmarshal: window mutated in unmarshal")
  80. }
  81. if !cloud1.Start.Equal(cloud2.Start) {
  82. t.Fatalf("Cloud Unmarshal: start mutated in unmarshal")
  83. }
  84. if !cloud1.End.Equal(cloud2.End) {
  85. t.Fatalf("Cloud Unmarshal: end mutated in unmarshal")
  86. }
  87. if cloud1.Adjustment != cloud2.Adjustment {
  88. t.Fatalf("Cloud Unmarshal: adjustment mutated in unmarshal")
  89. }
  90. if cloud1.Cost != cloud2.Cost {
  91. t.Fatalf("Cloud Unmarshal: cost mutated in unmarshal")
  92. }
  93. if cloud1.Credit != cloud2.Credit {
  94. t.Fatalf("Cloud Unmarshal: credit mutated in unmarshal")
  95. }
  96. // As a final check, make sure the above checks out
  97. if !cloud1.Equal(cloud2) {
  98. t.Fatalf("Cloud Unmarshal: Cloud mutated in unmarshal")
  99. }
  100. }
  101. func TestClusterManagement_Unmarshal(t *testing.T) {
  102. cm1 := NewClusterManagement(GCPProvider, "cluster1", unmarshalWindow)
  103. cm1.Cost = 9.0
  104. bytes, _ := json.Marshal(cm1)
  105. var testcm ClusterManagement
  106. cm2 := &testcm
  107. err := json.Unmarshal(bytes, cm2)
  108. // Check if unmarshal was successful
  109. if err != nil {
  110. t.Fatalf("ClusterManagement Unmarshal: unexpected error: %s", err)
  111. }
  112. // Check if all fields in initial ClusterManagement equal those in ClusterManagement from unmarshal
  113. if !cm1.Properties.Equal(cm2.Properties) {
  114. t.Fatalf("ClusterManagement Unmarshal: properties mutated in unmarshal")
  115. }
  116. if !cm1.Labels.Equal(cm2.Labels) {
  117. t.Fatalf("ClusterManagement Unmarshal: labels mutated in unmarshal")
  118. }
  119. if !cm1.Window.Equal(cm2.Window) {
  120. t.Fatalf("ClusterManagement Unmarshal: window mutated in unmarshal")
  121. }
  122. if cm1.Cost != cm2.Cost {
  123. t.Fatalf("ClusterManagement Unmarshal: cost mutated in unmarshal")
  124. }
  125. // As a final check, make sure the above checks out
  126. if !cm1.Equal(cm2) {
  127. t.Fatalf("ClusterManagement Unmarshal: ClusterManagement mutated in unmarshal")
  128. }
  129. }
  130. func TestDisk_Unmarshal(t *testing.T) {
  131. hours := unmarshalWindow.Duration().Hours()
  132. disk1 := NewDisk("disk1", "cluster1", "disk1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  133. disk1.ByteHours = 60.0 * gb * hours
  134. used := 40.0 * gb * hours
  135. disk1.ByteHoursUsed = &used
  136. max := 50.0 * gb * hours
  137. disk1.ByteUsageMax = &max
  138. disk1.Cost = 4.0
  139. disk1.Local = 1.0
  140. disk1.SetAdjustment(1.0)
  141. disk1.Breakdown = &Breakdown{
  142. Idle: 0.1,
  143. System: 0.2,
  144. User: 0.3,
  145. Other: 0.4,
  146. }
  147. bytes, _ := json.Marshal(disk1)
  148. var testdisk Disk
  149. disk2 := &testdisk
  150. err := json.Unmarshal(bytes, disk2)
  151. // Check if unmarshal was successful
  152. if err != nil {
  153. t.Fatalf("Disk Unmarshal: unexpected error: %s", err)
  154. }
  155. // Check if all fields in initial Disk equal those in Disk from unmarshal
  156. if !disk1.Properties.Equal(disk2.Properties) {
  157. t.Fatalf("Disk Unmarshal: properties mutated in unmarshal")
  158. }
  159. if !disk1.Labels.Equal(disk2.Labels) {
  160. t.Fatalf("Disk Unmarshal: labels mutated in unmarshal")
  161. }
  162. if !disk1.Window.Equal(disk2.Window) {
  163. t.Fatalf("Disk Unmarshal: window mutated in unmarshal")
  164. }
  165. if !disk1.Breakdown.Equal(disk2.Breakdown) {
  166. t.Fatalf("Disk Unmarshal: Breakdown mutated in unmarshal")
  167. }
  168. if !disk1.Start.Equal(disk2.Start) {
  169. t.Fatalf("Disk Unmarshal: start mutated in unmarshal")
  170. }
  171. if !disk1.End.Equal(disk2.End) {
  172. t.Fatalf("Disk Unmarshal: end mutated in unmarshal")
  173. }
  174. if disk1.Adjustment != disk2.Adjustment {
  175. t.Fatalf("Disk Unmarshal: adjustment mutated in unmarshal")
  176. }
  177. if disk1.ByteHours != disk2.ByteHours {
  178. t.Fatalf("Disk Unmarshal: ByteHours mutated in unmarshal")
  179. }
  180. if *disk1.ByteHoursUsed != *disk2.ByteHoursUsed {
  181. t.Fatalf("Disk Unmarshal: ByteHoursUsed mutated in unmarshal")
  182. }
  183. if *disk1.ByteUsageMax != *disk2.ByteUsageMax {
  184. t.Fatalf("Disk Unmarshal: ByteUsageMax mutated in unmarshal")
  185. }
  186. if disk1.Cost != disk2.Cost {
  187. t.Fatalf("Disk Unmarshal: cost mutated in unmarshal")
  188. }
  189. // Local from Disk is not marhsaled, and cannot be calculated from marshaled values.
  190. // Currently, it is just ignored and not set in the resulting unmarshal to Disk. Thus,
  191. // it is also ignored in this test; be aware that this means a resulting Disk from an
  192. // unmarshal is therefore NOT equal to the originally marshaled Disk.
  193. disk3 := NewDisk("disk3", "cluster1", "disk3", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  194. disk3.ByteHours = 60.0 * gb * hours
  195. disk3.ByteHoursUsed = nil
  196. disk3.ByteUsageMax = nil
  197. disk3.Cost = 4.0
  198. disk3.Local = 1.0
  199. disk3.SetAdjustment(1.0)
  200. disk3.Breakdown = &Breakdown{
  201. Idle: 0.1,
  202. System: 0.2,
  203. User: 0.3,
  204. Other: 0.4,
  205. }
  206. bytes, _ = json.Marshal(disk3)
  207. var testdisk2 Disk
  208. disk4 := &testdisk2
  209. err = json.Unmarshal(bytes, disk4)
  210. // Check if unmarshal was successful
  211. if err != nil {
  212. t.Fatalf("Disk Unmarshal: unexpected error: %s", err)
  213. }
  214. // Check that both disks have nil usage
  215. if disk3.ByteHoursUsed != disk4.ByteHoursUsed {
  216. t.Fatalf("Disk Unmarshal: ByteHoursUsed mutated in unmarshal")
  217. }
  218. // Check that both disks have nil max usage
  219. if disk3.ByteUsageMax != disk4.ByteUsageMax {
  220. t.Fatalf("Disk Unmarshal: ByteUsageMax mutated in unmarshal")
  221. }
  222. }
  223. func TestNetwork_Unmarshal(t *testing.T) {
  224. network1 := NewNetwork("network1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  225. network1.Cost = 4.0
  226. network1.SetAdjustment(1.0)
  227. bytes, _ := json.Marshal(network1)
  228. var testnw Network
  229. network2 := &testnw
  230. err := json.Unmarshal(bytes, network2)
  231. // Check if unmarshal was successful
  232. if err != nil {
  233. t.Fatalf("Network Unmarshal: unexpected error: %s", err)
  234. }
  235. // Check if all fields in initial Network equal those in Network from unmarshal
  236. if !network1.Properties.Equal(network2.Properties) {
  237. t.Fatalf("Network Unmarshal: properties mutated in unmarshal")
  238. }
  239. if !network1.Labels.Equal(network2.Labels) {
  240. t.Fatalf("Network Unmarshal: labels mutated in unmarshal")
  241. }
  242. if !network1.Window.Equal(network2.Window) {
  243. t.Fatalf("Network Unmarshal: window mutated in unmarshal")
  244. }
  245. if !network1.Start.Equal(network2.Start) {
  246. t.Fatalf("Network Unmarshal: start mutated in unmarshal")
  247. }
  248. if !network1.End.Equal(network2.End) {
  249. t.Fatalf("Network Unmarshal: end mutated in unmarshal")
  250. }
  251. if network1.Adjustment != network2.Adjustment {
  252. t.Fatalf("Network Unmarshal: adjustment mutated in unmarshal")
  253. }
  254. if network1.Cost != network2.Cost {
  255. t.Fatalf("Network Unmarshal: cost mutated in unmarshal")
  256. }
  257. // As a final check, make sure the above checks out
  258. if !network1.Equal(network2) {
  259. t.Fatalf("Network Unmarshal: Network mutated in unmarshal")
  260. }
  261. }
  262. func TestNode_Unmarshal(t *testing.T) {
  263. hours := unmarshalWindow.Duration().Hours()
  264. node1 := NewNode("node1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  265. node1.CPUCoreHours = 1.0 * hours
  266. node1.RAMByteHours = 2.0 * gb * hours
  267. node1.GPUHours = 0.0 * hours
  268. node1.GPUCost = 0.0
  269. node1.CPUCost = 8.0
  270. node1.RAMCost = 4.0
  271. node1.Discount = 0.3
  272. node1.CPUBreakdown = &Breakdown{
  273. Idle: 0.6,
  274. System: 0.2,
  275. User: 0.2,
  276. Other: 0.0,
  277. }
  278. node1.RAMBreakdown = &Breakdown{
  279. Idle: 0.6,
  280. System: 0.2,
  281. User: 0.2,
  282. Other: 0.0,
  283. }
  284. node1.SetAdjustment(1.6)
  285. bytes, _ := json.Marshal(node1)
  286. var testnode Node
  287. node2 := &testnode
  288. err := json.Unmarshal(bytes, node2)
  289. // Check if unmarshal was successful
  290. if err != nil {
  291. t.Fatalf("Node Unmarshal: unexpected error: %s", err)
  292. }
  293. // Check if all fields in initial Node equal those in Node from unmarshal
  294. if !node1.Properties.Equal(node2.Properties) {
  295. t.Fatalf("Node Unmarshal: properties mutated in unmarshal")
  296. }
  297. if !node1.Labels.Equal(node2.Labels) {
  298. t.Fatalf("Node Unmarshal: labels mutated in unmarshal")
  299. }
  300. if !node1.Window.Equal(node2.Window) {
  301. t.Fatalf("Node Unmarshal: window mutated in unmarshal")
  302. }
  303. if !node1.CPUBreakdown.Equal(node2.CPUBreakdown) {
  304. t.Fatalf("Node Unmarshal: CPUBreakdown mutated in unmarshal")
  305. }
  306. if !node1.RAMBreakdown.Equal(node2.RAMBreakdown) {
  307. t.Fatalf("Node Unmarshal: RAMBreakdown mutated in unmarshal")
  308. }
  309. if !node1.Start.Equal(node2.Start) {
  310. t.Fatalf("Node Unmarshal: start mutated in unmarshal")
  311. }
  312. if !node1.End.Equal(node2.End) {
  313. t.Fatalf("Node Unmarshal: end mutated in unmarshal")
  314. }
  315. if node1.Adjustment != node2.Adjustment {
  316. t.Fatalf("Node Unmarshal: adjustment mutated in unmarshal")
  317. }
  318. if node1.NodeType != node2.NodeType {
  319. t.Fatalf("Node Unmarshal: NodeType mutated in unmarshal")
  320. }
  321. if node1.CPUCoreHours != node2.CPUCoreHours {
  322. t.Fatalf("Node Unmarshal: CPUCoreHours mutated in unmarshal")
  323. }
  324. if node1.RAMByteHours != node2.RAMByteHours {
  325. t.Fatalf("Node Unmarshal: RAMByteHours mutated in unmarshal")
  326. }
  327. if node1.GPUHours != node2.GPUHours {
  328. t.Fatalf("Node Unmarshal: GPUHours mutated in unmarshal")
  329. }
  330. if node1.CPUCost != node2.CPUCost {
  331. t.Fatalf("Node Unmarshal: CPUCost mutated in unmarshal")
  332. }
  333. if node1.GPUCost != node2.GPUCost {
  334. t.Fatalf("Node Unmarshal: GPUCost mutated in unmarshal")
  335. }
  336. if node1.GPUCount != node2.GPUCount {
  337. t.Fatalf("Node Unmarshal: GPUCount mutated in unmarshal")
  338. }
  339. if node1.RAMCost != node2.RAMCost {
  340. t.Fatalf("Node Unmarshal: RAMCost mutated in unmarshal")
  341. }
  342. if node1.Discount != node2.Discount {
  343. t.Fatalf("Node Unmarshal: Discount mutated in unmarshal")
  344. }
  345. if node1.Preemptible != node2.Preemptible {
  346. t.Fatalf("Node Unmarshal: Preemptible mutated in unmarshal")
  347. }
  348. // As a final check, make sure the above checks out
  349. if !node1.Equal(node2) {
  350. t.Fatalf("Node Unmarshal: Node mutated in unmarshal")
  351. }
  352. }
  353. func TestLoadBalancer_Unmarshal(t *testing.T) {
  354. lb1 := NewLoadBalancer("loadbalancer1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow, false, "127.0.0.1")
  355. lb1.Cost = 12.0
  356. lb1.SetAdjustment(4.0)
  357. bytes, _ := json.Marshal(lb1)
  358. var testlb LoadBalancer
  359. lb2 := &testlb
  360. err := json.Unmarshal(bytes, lb2)
  361. // Check if unmarshal was successful
  362. if err != nil {
  363. t.Fatalf("LoadBalancer Unmarshal: unexpected error: %s", err)
  364. }
  365. // Check if all fields in initial LoadBalancer equal those in LoadBalancer from unmarshal
  366. if !lb1.Properties.Equal(lb2.Properties) {
  367. t.Fatalf("LoadBalancer Unmarshal: properties mutated in unmarshal")
  368. }
  369. if !lb1.Labels.Equal(lb2.Labels) {
  370. t.Fatalf("LoadBalancer Unmarshal: labels mutated in unmarshal")
  371. }
  372. if !lb1.Window.Equal(lb2.Window) {
  373. t.Fatalf("LoadBalancer Unmarshal: window mutated in unmarshal")
  374. }
  375. if !lb1.Start.Equal(lb2.Start) {
  376. t.Fatalf("LoadBalancer Unmarshal: start mutated in unmarshal")
  377. }
  378. if !lb1.End.Equal(lb2.End) {
  379. t.Fatalf("LoadBalancer Unmarshal: end mutated in unmarshal")
  380. }
  381. if lb1.Adjustment != lb2.Adjustment {
  382. t.Fatalf("LoadBalancer Unmarshal: adjustment mutated in unmarshal")
  383. }
  384. if lb1.Cost != lb2.Cost {
  385. t.Fatalf("LoadBalancer Unmarshal: cost mutated in unmarshal")
  386. }
  387. if lb1.Private != lb2.Private {
  388. t.Fatalf("LoadBalancer Unmarshal: private mutated in unmarshal")
  389. }
  390. if lb1.Ip != lb2.Ip {
  391. t.Fatalf("LoadBalancer Unmarshal: ip mutated in unmarshal")
  392. }
  393. // As a final check, make sure the above checks out
  394. if !lb1.Equal(lb2) {
  395. t.Fatalf("LoadBalancer Unmarshal: LoadBalancer mutated in unmarshal")
  396. }
  397. }
  398. func TestSharedAsset_Unmarshal(t *testing.T) {
  399. sa1 := NewSharedAsset("sharedasset1", unmarshalWindow)
  400. sa1.Cost = 7.0
  401. bytes, _ := json.Marshal(sa1)
  402. var testsa SharedAsset
  403. sa2 := &testsa
  404. err := json.Unmarshal(bytes, sa2)
  405. // Check if unmarshal was successful
  406. if err != nil {
  407. t.Fatalf("SharedAsset Unmarshal: unexpected error: %s", err)
  408. }
  409. // Check if all fields in initial SharedAsset equal those in SharedAsset from unmarshal
  410. if !sa1.Properties.Equal(sa2.Properties) {
  411. t.Fatalf("SharedAsset Unmarshal: properties mutated in unmarshal")
  412. }
  413. if !sa1.Labels.Equal(sa2.Labels) {
  414. t.Fatalf("SharedAsset Unmarshal: labels mutated in unmarshal")
  415. }
  416. if !sa1.Window.Equal(sa2.Window) {
  417. t.Fatalf("SharedAsset Unmarshal: window mutated in unmarshal")
  418. }
  419. if sa1.Cost != sa2.Cost {
  420. t.Fatalf("SharedAsset Unmarshal: cost mutated in unmarshal")
  421. }
  422. // As a final check, make sure the above checks out
  423. if !sa1.Equal(sa2) {
  424. t.Fatalf("SharedAsset Unmarshal: SharedAsset mutated in unmarshal")
  425. }
  426. }
  427. func TestAssetset_Unmarshal(t *testing.T) {
  428. var s time.Time
  429. var e time.Time
  430. unmarshalWindow := NewWindow(&s, &e)
  431. any := NewAsset(*unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  432. cloud := NewCloud("Compute", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  433. cm := NewClusterManagement(GCPProvider, "cluster1", unmarshalWindow)
  434. disk := NewDisk("disk1", "cluster1", "disk1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  435. network := NewNetwork("network1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  436. node := NewNode("node1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow)
  437. lb := NewLoadBalancer("loadbalancer1", "cluster1", "provider1", *unmarshalWindow.start, *unmarshalWindow.end, unmarshalWindow, false, "127.0.0.1")
  438. sa := NewSharedAsset("sharedasset1", unmarshalWindow)
  439. assetList := []Asset{any, cloud, cm, disk, network, node, lb, sa}
  440. assetset := NewAssetSet(s, e, assetList...)
  441. bytes, _ := json.Marshal(assetset)
  442. var assetSetResponse AssetSetResponse
  443. assetUnmarshalResponse := &assetSetResponse
  444. err := json.Unmarshal(bytes, assetUnmarshalResponse)
  445. // Check if unmarshal was successful
  446. if err != nil {
  447. t.Fatalf("AssetSet Unmarshal: unexpected error: %s", err)
  448. }
  449. // For each asset in unmarshaled AssetSetResponse, check if it is equal to the corresponding AssetSet asset
  450. for key, asset := range assetset.Assets {
  451. if unmarshaledAsset, exists := assetUnmarshalResponse.Assets[key]; exists {
  452. // As Disk is not marshaled with all fields, the resultant Disk will be unequal. Test all fields we have instead.
  453. if unmarshaledAsset.Type().String() == "Disk" {
  454. udiskEq := func(d1 Asset, d2 Asset) bool {
  455. asset, _ := asset.(*Disk)
  456. unmarshaledAsset, _ := unmarshaledAsset.(*Disk)
  457. if !asset.GetLabels().Equal(unmarshaledAsset.Labels) {
  458. return false
  459. }
  460. if !asset.Properties.Equal(unmarshaledAsset.Properties) {
  461. return false
  462. }
  463. if !asset.GetStart().Equal(unmarshaledAsset.Start) {
  464. return false
  465. }
  466. if !asset.End.Equal(unmarshaledAsset.End) {
  467. return false
  468. }
  469. if !asset.Window.Equal(unmarshaledAsset.Window) {
  470. return false
  471. }
  472. if asset.Adjustment != unmarshaledAsset.Adjustment {
  473. return false
  474. }
  475. if asset.Cost != unmarshaledAsset.Cost {
  476. return false
  477. }
  478. if asset.ByteHours != unmarshaledAsset.ByteHours {
  479. return false
  480. }
  481. if !asset.Breakdown.Equal(unmarshaledAsset.Breakdown) {
  482. return false
  483. }
  484. return true
  485. }
  486. if res := udiskEq(asset, unmarshaledAsset); !res {
  487. t.Fatalf("AssetSet Unmarshal: asset at key '%s' from unmarshaled AssetSetResponse does not match corresponding asset from AssetSet", key)
  488. }
  489. } else {
  490. if !asset.Equal(unmarshaledAsset) {
  491. t.Fatalf("AssetSet Unmarshal: asset at key '%s' from unmarshaled AssetSetResponse does not match corresponding asset from AssetSet", key)
  492. }
  493. }
  494. } else {
  495. t.Fatalf("AssetSet Unmarshal: key '%s' from marshaled AssetSet does not exist in AssetSetResponse", key)
  496. }
  497. }
  498. }