service_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2025 BackendServerTemplate Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package resource
  5. import (
  6. "fmt"
  7. "strings"
  8. "testing"
  9. )
  10. func TestServiceConfig(t *testing.T) {
  11. if ServiceConfig.Name == "" {
  12. t.Errorf("Service name is empty")
  13. }
  14. if ServiceConfig.DisplayName == "" {
  15. t.Errorf("Service display name is empty")
  16. }
  17. if strings.Contains(ServiceConfig.Describe, "\n") {
  18. t.Errorf("Service describe has LF")
  19. }
  20. if strings.Contains(ServiceConfig.Describe, "\r") {
  21. t.Errorf("Service describe has CR")
  22. }
  23. if len(ServiceConfig.Describe) > 1 && ServiceConfig.Describe[0] == ' ' {
  24. t.Errorf("Service describe start with space")
  25. }
  26. if len(ServiceConfig.Describe) > 2 && ServiceConfig.Describe[len(ServiceConfig.Describe)-1] == ' ' {
  27. t.Errorf("Service describe end with space")
  28. }
  29. switch ServiceConfig.ArgumentFrom {
  30. case FromConfig:
  31. if len(ServiceConfig.ArgumentList) == 0 {
  32. t.Errorf("Error argument-from: argument-list is empty, but argument-from config")
  33. }
  34. case FromNo:
  35. if len(ServiceConfig.ArgumentList) > 0 {
  36. t.Errorf("Error argument-from: argument-list is not empty, but argument-from no")
  37. }
  38. default:
  39. t.Errorf(fmt.Sprintf("Error argument-from: %s", ServiceConfig.ArgumentFrom))
  40. }
  41. switch ServiceConfig.EnvFrom {
  42. case FromConfig:
  43. if len(ServiceConfig.EnvSetList) == 0 {
  44. t.Errorf("Error env-from: env-set-list is empty, but env-from config")
  45. }
  46. case FromNo:
  47. if len(ServiceConfig.EnvSetList) > 0 {
  48. t.Errorf("Error env-from: env-set-list is not empty, but env-from no")
  49. }
  50. default:
  51. t.Errorf(fmt.Sprintf("Error argument-from: %s", ServiceConfig.EnvFrom))
  52. }
  53. }