qemu_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package qemu
  15. import (
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. )
  19. func Test_baseOptions(t *testing.T) {
  20. opt := newBaseOptions_x86_64()
  21. assert := assert.New(t)
  22. // test object
  23. assert.Equal("-object iothread,id=iothread0", opt.Object("iothread", map[string]string{"id": "iothread0"}))
  24. // test chardev
  25. assert.Equal("-chardev socket,id=test", opt.Chardev("socket", "test", ""))
  26. assert.Equal("-chardev socket,id=test,name=tname", opt.Chardev("socket", "test", "tname"))
  27. assert.Equal("-chardev socket,id=test,port=1234,host=127.0.0.1,nodelay,server,nowait", opt.MonitorChardev("test", 1234, "127.0.0.1"))
  28. assert.Equal([]string{
  29. "-chardev socket,id=testdev,port=1234,host=127.0.0.1,nodelay,server,nowait",
  30. "-mon chardev=testdev,id=test,mode=readline",
  31. }, getMonitorOptions(opt, &Monitor{
  32. Id: "test",
  33. Port: 1234,
  34. Mode: "readline",
  35. }))
  36. // test device
  37. assert.Equal("-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc", opt.Device("isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"))
  38. // test vnc
  39. assert.Equal("-vnc :5900,password", opt.VNC(5900, true))
  40. assert.Equal("-vnc :5900", opt.VNC(5900, false))
  41. }