<commit_before>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"v.io/jiri/collect"
	"v.io/jiri/project"
	"v.io/jiri/runutil"
	"v.io/jiri/tool"
	"v.io/x/devtools/internal/test"
)

const (
	scriptEnvVar        = "CREATE_INSTANCE_SCRIPT"
	testInstancePrefix  = "create-instance-test"
	testInstanceProject = "vanadium-internal"
	testInstanceZone    = "us-central1-c"
)

var (
	defaultCreateInstanceTimeout = time.Minute * 10
	defaultCheckInstanceTimeout  = time.Minute * 5
)

type instance struct {
	Name              string
	Zone              string
	NetworkInterfaces []struct {
		AccessConfigs []struct {
			NatIP string
		}
	}
}

// vanadiumCreateInstanceTest creates a test instance using the
// create_instance.sh script (specified in the CREATE_INSTANCE_SCRIPT
// environment variable) and run prod service test and load test againest it.
func vanadiumCreateInstanceTest(ctx *tool.Context, testName string, opts ...Opt) (_ *test.Result, e error) {
	root, err := project.JiriRoot()
	if err != nil {
		return nil, err
	}

	// Check CREATE_INSTANCE_SCRIPT environment variable.
	script := os.Getenv(scriptEnvVar)
	if script == "" {
		return nil, internalTestError{fmt.Errorf("script not defined in %s environment variable", scriptEnvVar), "Env"}
	}

	cleanup, err := initTest(ctx, testName, []string{"base"})
	if err != nil {
		return nil, internalTestError{err, "Init"}
	}
	defer collect.Error(func() error { return cleanup() }, &e)
<commit_msg>TBR: jiri-test/internal/test/create_instance.go: Add Env Var for project.<commit_after>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"v.io/jiri/collect"
	"v.io/jiri/project"
	"v.io/jiri/runutil"
	"v.io/jiri/tool"
	"v.io/x/devtools/internal/test"
)

const (
	scriptEnvVar       = "CREATE_INSTANCE_SCRIPT"
	projectEnvVar      = "CREATE_INSTANCE_PROJECT_ID"
	testInstancePrefix = "create-instance-test"
	testInstanceZone   = "us-central1-c"
)

var (
	defaultCreateInstanceTimeout = time.Minute * 10
	defaultCheckInstanceTimeout  = time.Minute * 5
	testInstanceProject          = os.Getenv(projectEnvVar)
)

type instance struct {
	Name              string
	Zone              string
	NetworkInterfaces []struct {
		AccessConfigs []struct {
			NatIP string
		}
	}
}

// vanadiumCreateInstanceTest creates a test instance using the
// create_instance.sh script (specified in the CREATE_INSTANCE_SCRIPT
// environment variable) and run prod service test and load test againest it.
func vanadiumCreateInstanceTest(ctx *tool.Context, testName string, opts ...Opt) (_ *test.Result, e error) {
	root, err := project.JiriRoot()
	if err != nil {
		return nil, err
	}

	if testInstanceProject == "" {
		return nil, internalTestError{fmt.Errorf("project not defined in %s environment variable", projectEnvVar), "Env"}
	}

	// Check CREATE_INSTANCE_SCRIPT environment variable.
	script := os.Getenv(scriptEnvVar)
	if script == "" {
		return nil, internalTestError{fmt.Errorf("script not defined in %s environment variable", scriptEnvVar), "Env"}
	}

	cleanup, err := initTest(ctx, testName, []string{"base"})
	if err != nil {
		return nil, internalTestError{err, "Init"}
	}
	defer collect.Error(func() error { return cleanup() }, &e)

{'fraction_non_alphanumeric': 0.11519198664440734, 'fraction_numerical': 0.004451864218141347, 'mean_word_length': 3.851551956815115, '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': '2355284', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1166, 'n_words': 327}