metrics_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright 2020 Docker, Inc.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package server
  14. import (
  15. "context"
  16. "strings"
  17. "testing"
  18. "google.golang.org/grpc"
  19. "gotest.tools/v3/assert"
  20. containersv1 "github.com/docker/compose-cli/protos/containers/v1"
  21. contextsv1 "github.com/docker/compose-cli/protos/contexts/v1"
  22. streamsv1 "github.com/docker/compose-cli/protos/streams/v1"
  23. "github.com/docker/compose-cli/server/proxy"
  24. )
  25. func TestAllMethodsHaveCorrespondingCliCommand(t *testing.T) {
  26. s := setupServer()
  27. i := s.GetServiceInfo()
  28. for k, v := range i {
  29. if k == "grpc.health.v1.Health" {
  30. continue
  31. }
  32. var errs []string
  33. for _, m := range v.Methods {
  34. name := "/" + k + "/" + m.Name
  35. if _, keyExists := methodMapping[name]; !keyExists {
  36. errs = append(errs, name+" not mapped to a corresponding cli command")
  37. }
  38. }
  39. assert.Equal(t, "", strings.Join(errs, "\n"))
  40. }
  41. }
  42. func setupServer() *grpc.Server {
  43. ctx := context.TODO()
  44. s := New(ctx)
  45. p := proxy.New(ctx)
  46. containersv1.RegisterContainersServer(s, p)
  47. streamsv1.RegisterStreamingServer(s, p)
  48. contextsv1.RegisterContextsServer(s, p.ContextsProxy())
  49. return s
  50. }