github.com/rothwerx/packer@v0.9.0/builder/parallels/common/driver_9_test.go (about) 1 package common 2 3 import ( 4 "io/ioutil" 5 "os" 6 "testing" 7 ) 8 9 func TestParallels9Driver_impl(t *testing.T) { 10 var _ Driver = new(Parallels9Driver) 11 } 12 13 func TestIpAddress(t *testing.T) { 14 tf, err := ioutil.TempFile("", "packer") 15 if err != nil { 16 t.Fatalf("err: %s", err) 17 } 18 defer os.Remove(tf.Name()) 19 20 d := Parallels9Driver{ 21 dhcp_lease_file: tf.Name(), 22 } 23 24 // No lease should be found in an empty file 25 ip, err := d.IpAddress("123456789012") 26 if err == nil { 27 t.Fatalf("Found IP: \"%v\". No IP should be found!\n", ip) 28 } 29 30 // The most recent lease, 10.211.55.126 should be found 31 c := []byte(` 32 [vnic0] 33 10.211.55.125="1418288000,1800,001c4235240c,ff4235240c000100011c1c10e7001c4235240c" 34 10.211.55.126="1418288969,1800,001c4235240c,ff4235240c000100011c1c11ad001c4235240c" 35 10.211.55.254="1411712008,1800,001c42a51419,01001c42a51419" 36 `) 37 ioutil.WriteFile(tf.Name(), c, 0666) 38 ip, err = d.IpAddress("001C4235240c") 39 if err != nil { 40 t.Fatalf("Error: %v\n", err) 41 } 42 if ip != "10.211.55.126" { 43 t.Fatalf("Should have found 10.211.55.126, not %s!\n", ip) 44 } 45 46 // The most recent lease, 10.211.55.124 should be found 47 c = []byte(`[vnic0] 48 10.211.55.124="1418288969,1800,001c4235240c,ff4235240c000100011c1c11ad001c4235240c" 49 10.211.55.125="1418288000,1800,001c4235240c,ff4235240c000100011c1c10e7001c4235240c" 50 10.211.55.254="1411712008,1800,001c42a51419,01001c42a51419" 51 `) 52 ioutil.WriteFile(tf.Name(), c, 0666) 53 ip, err = d.IpAddress("001c4235240c") 54 if err != nil { 55 t.Fatalf("Error: %v\n", err) 56 } 57 if ip != "10.211.55.124" { 58 t.Fatalf("Should have found 10.211.55.124, not %s!\n", ip) 59 } 60 }