env_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2015 CoreOS, Inc.
  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 system
  15. import (
  16. "testing"
  17. )
  18. func TestServiceContents(t *testing.T) {
  19. tests := []struct {
  20. Config interface{}
  21. Contents string
  22. }{
  23. {
  24. struct{}{},
  25. "",
  26. },
  27. {
  28. struct {
  29. A string `env:"A"`
  30. B int `env:"B"`
  31. C bool `env:"C"`
  32. D float64 `env:"D"`
  33. }{
  34. "hi", 1, true, 0.12345,
  35. },
  36. `[Service]
  37. Environment="A=hi"
  38. Environment="B=1"
  39. Environment="C=true"
  40. Environment="D=0.12345"
  41. `,
  42. },
  43. {
  44. struct {
  45. A float64 `env:"A"`
  46. B float64 `env:"B"`
  47. C float64 `env:"C"`
  48. D float64 `env:"D"`
  49. }{
  50. 0.000001, 1, 0.9999999, 0.1,
  51. },
  52. `[Service]
  53. Environment="A=1e-06"
  54. Environment="B=1"
  55. Environment="C=0.9999999"
  56. Environment="D=0.1"
  57. `,
  58. },
  59. }
  60. for _, tt := range tests {
  61. if c := serviceContents(tt.Config); c != tt.Contents {
  62. t.Errorf("bad contents (%+v): want %q, got %q", tt, tt.Contents, c)
  63. }
  64. }
  65. }