<commit_before>// Copyright 2018 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"
	"os"
	"strings"
	"testing"
)

func TestMain(t *testing.T) {
	t.Skip("Need to set GOOGLE_CLOUD_PROJECT")
	oldStdout := os.Stdout
	r, w, _ := os.Pipe()
	os.Stdout = w

	main()

	w.Close()
	os.Stdout = oldStdout

	out, err := ioutil.ReadAll(r)
	if err != nil {
		t.Fatalf("Failed to read stdout: %v", err)
	}
	got := string(out)
<commit_msg>jobs: enable quickstart test (#611)<commit_after>// Copyright 2018 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 (
	"context"
	"io/ioutil"
	"os"
	"strings"
	"testing"

	"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
	"golang.org/x/oauth2/google"
	talent "google.golang.org/api/jobs/v3"
)

func checkServiceAvailable(t *testing.T, projectID string) {
	client, err := google.DefaultClient(context.Background(), talent.CloudPlatformScope)
	if err != nil {
		t.Skipf("DefaultClient: %v", err)
	}

	service, err := talent.New(client)
	if err != nil {
		t.Skipf("createCTSService: service account likely in different project: %v", err)
	}
	if _, err := service.Projects.Companies.List("projects/" + projectID).Do(); err != nil {
		t.Skip("List: service account likely in different project")
	}
}

func TestMain(t *testing.T) {
	tc := testutil.SystemTest(t)
	checkServiceAvailable(t, tc.ProjectID)

	os.Setenv("GOOGLE_CLOUD_PROJECT", tc.ProjectID)

	oldStdout := os.Stdout
	r, w, _ := os.Pipe()
	os.Stdout = w

	main()

	w.Close()
	os.Stdout = oldStdout

	out, err := ioutil.ReadAll(r)
	if err != nil {
		t.Fatalf("Failed to read stdout: %v", err)
	}
	got := string(out)

{'fraction_non_alphanumeric': 0.1423160173160173, 'fraction_numerical': 0.0091991341991342, 'mean_word_length': 3.8915343915343916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '339730', 'n_tokens_mistral': 716, 'n_tokens_neox': 680, 'n_words': 188}