sysv_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 system_service
  15. import (
  16. "testing"
  17. )
  18. func TestParseSysv(t *testing.T) {
  19. cases := []struct {
  20. in1 string
  21. in2 string
  22. name string
  23. wantLoaded bool
  24. wantActive bool
  25. }{
  26. {`openvswitch 0:off 1:off 2:off 3:off 4:off 5:off 6:off`, `ovsdb-server is running with pid 114553
  27. ovs-vswitchd is running with pid 114563`, "openvswitch", true, true},
  28. {`yunion-host 0:off 1:off 2:on 3:on 4:on 5:on 6:off`, "", "yunion-host", true, false},
  29. }
  30. for _, c := range cases {
  31. status := parseSysvStatus(c.in1, c.in2, c.name)
  32. if status.Loaded != c.wantLoaded || status.Active != c.wantActive {
  33. t.Errorf("parseSysVStatus %s Loaded want %v got %v Active want %v got %v", c.name, c.wantLoaded, status.Loaded, c.wantActive, status.Active)
  34. }
  35. }
  36. }