...

Source file src/google.golang.org/api/internal/examples/mock/lowlevel_test.go

Documentation: google.golang.org/api/internal/examples/mock

     1  // Copyright 2021 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mock
     6  
     7  import (
     8  	"testing"
     9  
    10  	"google.golang.org/api/googleapi"
    11  	"google.golang.org/api/translate/v3"
    12  )
    13  
    14  // mockCall fullfills the TranslateTextCall and matches the `Do` call on
    15  // `translate.ProjectsTranslateTextCall`.
    16  type mockCall struct{}
    17  
    18  func (*mockCall) Do(opts ...googleapi.CallOption) (*translate.TranslateTextResponse, error) {
    19  	resp := &translate.TranslateTextResponse{
    20  		Translations: []*translate.Translation{
    21  			{TranslatedText: "Hello World"},
    22  		},
    23  	}
    24  	return resp, nil
    25  }
    26  
    27  func TestTranslateTextLowLevel(t *testing.T) {
    28  	call := &mockCall{}
    29  	text, err := TranslateTextLowLevel(call)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	if text != "Hello World" {
    34  		t.Fatalf("got %q, want Hello World", text)
    35  	}
    36  }
    37  

View as plain text