<commit_before>// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package main

import (
	"io/ioutil"
	"testing"

	"golang.org/x/net/context"
	"google.golang.org/api/option"
	"google.golang.org/api/transport"
	speech "google.golang.org/genproto/googleapis/cloud/speech/v1"
)

func TestRecognize(t *testing.T) {
	ctx := context.Background()

	conn, err := transport.DialGRPC(ctx,
		option.WithEndpoint("speech.googleapis.com:443"),
		option.WithScopes("https://www.googleapis.com/auth/cloud-platform"),
	)
	if err != nil {
		t.Fatal(err)
	}
	defer conn.Close()
	c := speech.NewSpeechClient(conn)

	data, err := ioutil.ReadFile("./quit.raw")
	if err != nil {
		t.Fatal(err)
	}

	rresp, err := recognize(ctx, c, &data)
	if err != nil {
		t.Fatal(err)
	}
	if len(rresp.Responses) < 1 {
		t.Fatal("want recognize responses; got none")
	}

	resp := rresp.Responses[0]
	if resp.Error != nil {
		t.Fatalf("got error from response: %v", err)
	}
	if len(resp.Results) < 1 {
		t.Fatal("want results; got none")
	}
	if len(resp.Results[0].Alternatives) < 1 {
		t.Fatal("want alternatives; got none")
	}
	if got, want := resp.Results[0].Alternatives[0].Transcript, "quit"; got != want {
		t.Errorf("want transcript: %q; got %q", want, got)
	}
}
<commit_msg>speech/transcript: fix the failing test (#83)<commit_after>// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package main

import (
	"io/ioutil"
	"testing"

	"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"

	"golang.org/x/net/context"
	"google.golang.org/api/option"
	"google.golang.org/api/transport"
	speech "google.golang.org/genproto/googleapis/cloud/speech/v1"
)

func TestRecognize(t *testing.T) {
	testutil.SystemTest(t)

	ctx := context.Background()
	conn, err := transport.DialGRPC(ctx,
		option.WithEndpoint("speech.googleapis.com:443"),
		option.WithScopes("https://www.googleapis.com/auth/cloud-platform"),
	)
	if err != nil {
		t.Fatal(err)
	}
	defer conn.Close()
	c := speech.NewSpeechClient(conn)

	data, err := ioutil.ReadFile("./quit.raw")
	if err != nil {
		t.Fatal(err)
	}

	rresp, err := recognize(ctx, c, &data)
	if err != nil {
		t.Fatal(err)
	}
	if len(rresp.Responses) < 1 {
		t.Fatal("want recognize responses; got none")
	}

	resp := rresp.Responses[0]
	if resp.Error != nil {
		t.Fatalf("got error from response: %v", err)
	}
	if len(resp.Results) < 1 {
		t.Fatal("got no results; want at least one")
	}
	if len(resp.Results[0].Alternatives) < 1 {
		t.Fatal("got no alternatives; want at least one")
	}
	if got, want := resp.Results[0].Alternatives[0].Transcript, "quit"; got != want {
		t.Errorf("got transcript: %q; want %q", got, want)
	}
}

{'fraction_non_alphanumeric': 0.16140350877192983, 'fraction_numerical': 0.01263157894736842, 'mean_word_length': 3.840407470288625, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6327951', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1047, 'n_words': 251}