coreosutils_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 coreosutils
  15. import (
  16. "fmt"
  17. "testing"
  18. )
  19. func TestSCloudConfig_String(t *testing.T) {
  20. cc := NewCloudConfig()
  21. cc.YunionInit()
  22. cc.SetHostname("coreos1")
  23. cont := "[Match]\n"
  24. cont += "Name=eth*\n\n"
  25. cont += "[Network]\n"
  26. cont += "DHCP=yes\n"
  27. runtime := true
  28. cc.AddUnits("00-dhcp.network", nil, nil, &runtime, cont, "", nil)
  29. cont = "/dev/vdb1 swap defaults 0 0\n"
  30. cont += "/dev/vdc1 /data ext4 defaults 2 2\n"
  31. cc.AddWriteFile("/etc/fstab", cont, "", "", false)
  32. cc.SetEtcHosts("localhost")
  33. cc.AddUser("core", "123456", nil, false)
  34. cc.AddUser("core1", "123456", []string{"ssh-rsa xxxxx", "ssh-dsa xxxxxxxxx"}, false)
  35. cc.AddSwap("/dev/vdb1")
  36. cc.AddPartition("/dev/vdc1", "/data", "ext4")
  37. cc.SetTimezone("Asia/Shanghai")
  38. fmt.Println(cc)
  39. }