25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

54 satır
1.6 KiB

  1. // Copyright 2018 Google LLC
  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 trace
  15. import (
  16. "errors"
  17. "net/http"
  18. "testing"
  19. "cloud.google.com/go/internal/testutil"
  20. octrace "go.opencensus.io/trace"
  21. "google.golang.org/api/googleapi"
  22. "google.golang.org/genproto/googleapis/rpc/code"
  23. "google.golang.org/grpc/codes"
  24. "google.golang.org/grpc/status"
  25. )
  26. func TestToStatus(t *testing.T) {
  27. for _, testcase := range []struct {
  28. input error
  29. want octrace.Status
  30. }{
  31. {
  32. errors.New("some random error"),
  33. octrace.Status{Code: int32(code.Code_UNKNOWN), Message: "some random error"},
  34. },
  35. {
  36. &googleapi.Error{Code: http.StatusConflict, Message: "some specific googleapi http error"},
  37. octrace.Status{Code: int32(code.Code_ALREADY_EXISTS), Message: "some specific googleapi http error"},
  38. },
  39. {
  40. status.Error(codes.DataLoss, "some specific grpc error"),
  41. octrace.Status{Code: int32(code.Code_DATA_LOSS), Message: "some specific grpc error"},
  42. },
  43. } {
  44. got := toStatus(testcase.input)
  45. if r := testutil.Diff(got, testcase.want); r != "" {
  46. t.Errorf("got -, want +:\n%s", r)
  47. }
  48. }
  49. }