module_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2013 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package module
  5. import (
  6. "reflect"
  7. "testing"
  8. "github.com/golang/protobuf/proto"
  9. "google.golang.org/appengine/internal/aetesting"
  10. pb "google.golang.org/appengine/internal/modules"
  11. )
  12. const version = "test-version"
  13. const module = "test-module"
  14. const instances = 3
  15. func TestList(t *testing.T) {
  16. c := aetesting.FakeSingleContext(t, "modules", "GetModules", func(req *pb.GetModulesRequest, res *pb.GetModulesResponse) error {
  17. res.Module = []string{"default", "mod1"}
  18. return nil
  19. })
  20. got, err := List(c)
  21. if err != nil {
  22. t.Fatalf("List: %v", err)
  23. }
  24. want := []string{"default", "mod1"}
  25. if !reflect.DeepEqual(got, want) {
  26. t.Errorf("List = %v, want %v", got, want)
  27. }
  28. }
  29. func TestSetNumInstances(t *testing.T) {
  30. c := aetesting.FakeSingleContext(t, "modules", "SetNumInstances", func(req *pb.SetNumInstancesRequest, res *pb.SetNumInstancesResponse) error {
  31. if *req.Module != module {
  32. t.Errorf("Module = %v, want %v", req.Module, module)
  33. }
  34. if *req.Version != version {
  35. t.Errorf("Version = %v, want %v", req.Version, version)
  36. }
  37. if *req.Instances != instances {
  38. t.Errorf("Instances = %v, want %d", req.Instances, instances)
  39. }
  40. return nil
  41. })
  42. err := SetNumInstances(c, module, version, instances)
  43. if err != nil {
  44. t.Fatalf("SetNumInstances: %v", err)
  45. }
  46. }
  47. func TestVersions(t *testing.T) {
  48. c := aetesting.FakeSingleContext(t, "modules", "GetVersions", func(req *pb.GetVersionsRequest, res *pb.GetVersionsResponse) error {
  49. if *req.Module != module {
  50. t.Errorf("Module = %v, want %v", req.Module, module)
  51. }
  52. res.Version = []string{"v1", "v2", "v3"}
  53. return nil
  54. })
  55. got, err := Versions(c, module)
  56. if err != nil {
  57. t.Fatalf("Versions: %v", err)
  58. }
  59. want := []string{"v1", "v2", "v3"}
  60. if !reflect.DeepEqual(got, want) {
  61. t.Errorf("Versions = %v, want %v", got, want)
  62. }
  63. }
  64. func TestDefaultVersion(t *testing.T) {
  65. c := aetesting.FakeSingleContext(t, "modules", "GetDefaultVersion", func(req *pb.GetDefaultVersionRequest, res *pb.GetDefaultVersionResponse) error {
  66. if *req.Module != module {
  67. t.Errorf("Module = %v, want %v", req.Module, module)
  68. }
  69. res.Version = proto.String(version)
  70. return nil
  71. })
  72. got, err := DefaultVersion(c, module)
  73. if err != nil {
  74. t.Fatalf("DefaultVersion: %v", err)
  75. }
  76. if got != version {
  77. t.Errorf("Version = %v, want %v", got, version)
  78. }
  79. }
  80. func TestStart(t *testing.T) {
  81. c := aetesting.FakeSingleContext(t, "modules", "StartModule", func(req *pb.StartModuleRequest, res *pb.StartModuleResponse) error {
  82. if *req.Module != module {
  83. t.Errorf("Module = %v, want %v", req.Module, module)
  84. }
  85. if *req.Version != version {
  86. t.Errorf("Version = %v, want %v", req.Version, version)
  87. }
  88. return nil
  89. })
  90. err := Start(c, module, version)
  91. if err != nil {
  92. t.Fatalf("Start: %v", err)
  93. }
  94. }
  95. func TestStop(t *testing.T) {
  96. c := aetesting.FakeSingleContext(t, "modules", "StopModule", func(req *pb.StopModuleRequest, res *pb.StopModuleResponse) error {
  97. version := "test-version"
  98. module := "test-module"
  99. if *req.Module != module {
  100. t.Errorf("Module = %v, want %v", req.Module, module)
  101. }
  102. if *req.Version != version {
  103. t.Errorf("Version = %v, want %v", req.Version, version)
  104. }
  105. return nil
  106. })
  107. err := Stop(c, module, version)
  108. if err != nil {
  109. t.Fatalf("Stop: %v", err)
  110. }
  111. }