github.com/raghuse92/packer@v1.3.2/post-processor/vsphere/post-processor_test.go (about) 1 package vsphere 2 3 import ( 4 "fmt" 5 "net/url" 6 "strings" 7 "testing" 8 ) 9 10 func TestArgs(t *testing.T) { 11 var p PostProcessor 12 13 p.config.Username = "me" 14 p.config.Password = "notpassword" 15 p.config.Host = "myhost" 16 p.config.Datacenter = "mydc" 17 p.config.Cluster = "mycluster" 18 p.config.VMName = "my vm" 19 p.config.Datastore = "my datastore" 20 p.config.Insecure = true 21 p.config.DiskMode = "thin" 22 p.config.VMFolder = "my folder" 23 24 source := "something.vmx" 25 ovftool_uri := fmt.Sprintf("vi://%s:%s@%s/%s/host/%s", 26 url.QueryEscape(p.config.Username), 27 url.QueryEscape(p.config.Password), 28 p.config.Host, 29 p.config.Datacenter, 30 p.config.Cluster) 31 32 if p.config.ResourcePool != "" { 33 ovftool_uri += "/Resources/" + p.config.ResourcePool 34 } 35 36 args, err := p.BuildArgs(source, ovftool_uri) 37 if err != nil { 38 t.Errorf("Error: %s", err) 39 } 40 41 t.Logf("ovftool %s", strings.Join(args, " ")) 42 } 43 44 func TestEscaping(t *testing.T) { 45 type escapeCases struct { 46 Input string 47 Expected string 48 } 49 50 cases := []escapeCases{ 51 {`this has spaces`, `this%20has%20spaces`}, 52 {`exclaimation_!`, `exclaimation_%21`}, 53 {`hash_#_dollar_$`, `hash_%23_dollar_%24`}, 54 {`ampersand_&awesome`, `ampersand_%26awesome`}, 55 {`single_quote_'_and_another_'`, `single_quote_%27_and_another_%27`}, 56 {`open_paren_(_close_paren_)`, `open_paren_%28_close_paren_%29`}, 57 {`asterisk_*_plus_+`, `asterisk_%2A_plus_%2B`}, 58 {`comma_,slash_/`, `comma_%2Cslash_%2F`}, 59 {`colon_:semicolon_;`, `colon_%3Asemicolon_%3B`}, 60 {`equal_=question_?`, `equal_%3Dquestion_%3F`}, 61 {`at_@`, `at_%40`}, 62 {`open_bracket_[closed_bracket]`, `open_bracket_%5Bclosed_bracket%5D`}, 63 {`user:password with $paces@host/name.foo`, `user%3Apassword%20with%20%24paces%40host%2Fname.foo`}, 64 } 65 for _, escapeCase := range cases { 66 received := escapeWithSpaces(escapeCase.Input) 67 68 if escapeCase.Expected != received { 69 t.Errorf("Error escaping URL; expected %s got %s", escapeCase.Expected, received) 70 } 71 } 72 73 }