github.com/iDigitalFlame/xmt@v0.5.4/device/machine_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package device 18 19 import ( 20 "testing" 21 22 "github.com/iDigitalFlame/xmt/data" 23 "github.com/iDigitalFlame/xmt/device/arch" 24 ) 25 26 // marshal a machine here 27 28 func TestMachine(t *testing.T) { 29 m := &Machine{ 30 User: "Test123", 31 Version: "Some Linux OS", 32 Hostname: "Test Machine", 33 PID: 123, 34 PPID: 4567, 35 Network: Network{ 36 device{ 37 Name: "my_device", 38 Mac: 0xABCEEF012, 39 Address: []Address{ 40 Address{hi: 0xFFFF, low: 0xABCDE}, 41 }, 42 }, 43 }, 44 Capabilities: 0xABCD, 45 System: uint8(Windows)<<4 | uint8(arch.ARM64), 46 Elevated: 129, 47 } 48 m.ID[0] = 'A' 49 m.ID[MachineIDSize] = 'A' 50 m.ID.Seed([]byte("ABCD")) 51 52 var c data.Chunk 53 if err := m.MarshalStream(&c); err != nil { 54 t.Fatalf("TestMachine(): MarshalStream returned an error: %s", err.Error()) 55 } 56 57 c.Seek(0, 0) 58 59 var g Machine 60 if err := g.UnmarshalStream(&c); err != nil { 61 t.Fatalf("TestMachine(): UnmarshalStream returned an error: %s", err.Error()) 62 } 63 64 if g.ID != m.ID { 65 t.Fatalf(`TestMachine(): Machine ID "%s" does not match "%s".`, g.ID.Full(), m.ID.Full()) 66 } 67 if g.ID.Signature() != m.ID.Signature() { 68 t.Fatalf(`TestMachine(): Machine ID Signature "%s" does not match "%s".`, g.ID.Signature(), m.ID.Signature()) 69 } 70 if g.User != m.User { 71 t.Fatalf(`TestMachine(): Machine User "%s" does not match "%s".`, g.User, m.User) 72 } 73 if g.Version != m.Version { 74 t.Fatalf(`TestMachine(): Machine Version "%s" does not match "%s".`, g.Version, m.Version) 75 } 76 if g.Hostname != m.Hostname { 77 t.Fatalf(`TestMachine(): Machine Hostname "%s" does not match "%s".`, g.Hostname, m.Hostname) 78 } 79 if g.PID != m.PID { 80 t.Fatalf(`TestMachine(): Machine Hostname "%d" does not match "%d".`, g.PID, m.PID) 81 } 82 if g.PPID != m.PPID { 83 t.Fatalf(`TestMachine(): Machine Hostname "%d" does not match "%d".`, g.PPID, m.PPID) 84 } 85 if g.System != m.System { 86 t.Fatalf(`TestMachine(): Machine System "%d" does not match "%d".`, g.System, m.System) 87 } 88 if g.Network[0].Address[0].String() != m.Network[0].Address[0].String() { 89 t.Fatalf(`TestMachine(): Machine Address[0] "%s" does not match "%s".`, g.Network[0].Address[0].String(), m.Network[0].Address[0].String()) 90 } 91 }