How to use DownloadArtifacts method of tests Package

Best Testkube code snippet using tests.DownloadArtifacts

enumerate.go

Source:enumerate.go Github

copy

Full Screen

1// Copyright 2098 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4package cmd5import (6 "context"7 "fmt"8 "io/ioutil"9 "os"10 "path/filepath"11 "infra/cmd/cros_test_platform/internal/autotest/artifacts"12 "infra/cmd/cros_test_platform/internal/autotest/testspec"13 "infra/cmd/cros_test_platform/internal/enumeration"14 "infra/cmd/cros_test_platform/internal/site"15 "github.com/maruel/subcommands"16 "go.chromium.org/chromiumos/infra/proto/go/chromite/api"17 "go.chromium.org/chromiumos/infra/proto/go/test_platform/steps"18 "go.chromium.org/luci/auth/client/authcli"19 "go.chromium.org/luci/common/cli"20 "go.chromium.org/luci/common/errors"21 "go.chromium.org/luci/common/gcloud/gs"22)23// Enumerate is the `enumerate` subcommand implementation.24var Enumerate = &subcommands.Command{25 UsageLine: "enumerate -input_json /path/to/input.json -output_json /path/to/output.json",26 ShortDesc: "Enumerate tasks to execute for a request.",27 LongDesc: `Enumerate tasks to execute for a request.28Step input and output is JSON encoded protobuf defined at29https://chromium.googlesource.com/chromiumos/infra/proto/+/master/src/test_platform/steps/enumeration.proto`,30 CommandRun: func() subcommands.CommandRun {31 c := &enumerateRun{}32 c.authFlags.Register(&c.Flags, site.DefaultAuthOptions)33 c.Flags.StringVar(&c.inputPath, "input_json", "", "Path that contains JSON encoded test_platform.steps.EnumerationRequest")34 c.Flags.StringVar(&c.outputPath, "output_json", "", "Path where JSON encoded test_platform.steps.EnumerationResponse should be written.")35 return c36 },37}38type enumerateRun struct {39 subcommands.CommandRunBase40 authFlags authcli.Flags41 inputPath string42 outputPath string43}44func (c *enumerateRun) Run(a subcommands.Application, args []string, env subcommands.Env) int {45 err := c.innerRun(a, args, env)46 if err != nil {47 fmt.Fprintf(a.GetErr(), "%s\n", err)48 }49 return exitCode(err)50}51func (c *enumerateRun) innerRun(a subcommands.Application, args []string, env subcommands.Env) error {52 if err := c.processCLIArgs(args); err != nil {53 return err54 }55 var request steps.EnumerationRequest56 if err := readRequest(c.inputPath, &request); err != nil {57 return err58 }59 workspace, err := ioutil.TempDir("", "enumerate")60 if err != nil {61 return err62 }63 defer func() {64 os.RemoveAll(workspace)65 }()66 ctx := cli.GetContext(a, c, env)67 gsDir := gs.Path(request.GetMetadata().GetTestMetadataUrl())68 lp, err := c.downloadArtifacts(ctx, gsDir, workspace)69 if err != nil {70 return err71 }72 tm, err := computeMetadata(lp, workspace)73 if err != nil && tm == nil {74 // Catastrophic error. There is no reasonable response to write.75 return err76 }77 ts := c.enumerate(tm, &request)78 resp := steps.EnumerationResponse{AutotestTests: ts}79 return writeResponse(c.outputPath, &resp, err)80}81func (c *enumerateRun) processCLIArgs(args []string) error {82 if len(args) > 0 {83 return errors.Reason("have %d positional args, want 0", len(args)).Err()84 }85 if c.inputPath == "" {86 return errors.Reason("-input_json not specified").Err()87 }88 if c.outputPath == "" {89 return errors.Reason("-output_json not specified").Err()90 }91 return nil92}93func (c *enumerateRun) downloadArtifacts(ctx context.Context, gsDir gs.Path, workspace string) (artifacts.LocalPaths, error) {94 outDir := filepath.Join(workspace, "artifacts")95 if err := os.Mkdir(outDir, 0750); err != nil {96 return artifacts.LocalPaths{}, errors.Annotate(err, "download artifacts").Err()97 }98 client, err := c.newGSClient(ctx)99 if err != nil {100 return artifacts.LocalPaths{}, errors.Annotate(err, "download artifacts").Err()101 }102 lp, err := artifacts.DownloadFromGoogleStorage(client, gsDir, outDir)103 if err != nil {104 return artifacts.LocalPaths{}, errors.Annotate(err, "download artifacts").Err()105 }106 return lp, err107}108func (c *enumerateRun) newGSClient(ctx context.Context) (gs.Client, error) {109 t, err := newAuthenticatedTransport(ctx, &c.authFlags)110 if err != nil {111 return nil, errors.Annotate(err, "create GS client").Err()112 }113 return gs.NewProdClient(ctx, t)114}115func (c *enumerateRun) enumerate(tm *api.TestMetadataResponse, request *steps.EnumerationRequest) []*api.AutotestTest {116 var ts []*api.AutotestTest117 ts = append(ts, enumeration.GetForTests(tm.GetAutotest(), request.GetTests())...)118 ts = append(ts, enumeration.GetForSuites(tm.GetAutotest(), request.GetSuites())...)119 return ts120}121func computeMetadata(localPaths artifacts.LocalPaths, workspace string) (*api.TestMetadataResponse, error) {122 extracted := filepath.Join(workspace, "extracted")123 if err := os.Mkdir(extracted, 0750); err != nil {124 return nil, errors.Annotate(err, "compute metadata").Err()125 }126 if err := artifacts.ExtractControlFiles(localPaths, extracted); err != nil {127 return nil, errors.Annotate(err, "compute metadata").Err()128 }129 return testspec.Get(extracted)130}...

Full Screen

Full Screen

start.go

Source:start.go Github

copy

Full Screen

1/*2Copyright 2019 The Kubernetes Authors All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package perf14import (15 "context"16 "fmt"17 "io"18 "log"19 "os"20 "os/exec"21 "runtime"22 "github.com/pkg/errors"23)24const (25 // runs is the number of times each binary will be timed for 'minikube start'26 runs = 527 // threshold is the time difference in seconds we start alerting on28 threshold = 5.029)30// CompareMinikubeStart compares the time to run `minikube start` between two minikube binaries31func CompareMinikubeStart(ctx context.Context, out io.Writer, binaries []*Binary) error {32 drivers := []string{"kvm2", "docker"}33 if runtime.GOOS == "darwin" {34 drivers = []string{"hyperkit", "docker"}35 }36 runtimes := []string{"docker", "containerd"}37 for _, d := range drivers {38 for _, r := range runtimes {39 if !proceed(d, r) {40 continue41 }42 fmt.Printf("**%s driver with %s runtime**\n", d, r)43 if err := downloadArtifacts(ctx, binaries, d, r); err != nil {44 fmt.Printf("error downloading artifacts: %v", err)45 continue46 }47 rm, err := collectResults(ctx, binaries, d, r)48 if err != nil {49 fmt.Printf("error collecting results for %s driver: %v\n", d, err)50 continue51 }52 rm.summarizeResults(binaries)53 fmt.Println()54 }55 }56 return nil57}58func collectResults(ctx context.Context, binaries []*Binary, driver string, runtime string) (*resultManager, error) {59 rm := newResultManager()60 for run := 0; run < runs; run++ {61 log.Printf("Executing run %d/%d...", run+1, runs)62 for _, binary := range binaries {63 r, err := timeMinikubeStart(ctx, binary, driver, runtime)64 if err != nil {65 return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name())66 }67 rm.addResult(binary, "start", *r)68 if !skipIngress(driver) {69 r, err = timeEnableIngress(ctx, binary)70 if err != nil {71 return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name())72 }73 rm.addResult(binary, "ingress", *r)74 }75 deleteCmd := exec.CommandContext(ctx, binary.path, "delete")76 if err := deleteCmd.Run(); err != nil {77 log.Printf("error deleting minikube: %v", err)78 }79 }80 }81 return rm, nil82}83func average(nums []float64) float64 {84 total := float64(0)85 for _, a := range nums {86 total += a87 }88 return total / float64(len(nums))89}90func downloadArtifacts(ctx context.Context, binaries []*Binary, driver string, runtime string) error {91 for _, b := range binaries {92 c := exec.CommandContext(ctx, b.path, "start", fmt.Sprintf("--driver=%s", driver), fmt.Sprintf("--container-runtime=%s", runtime))93 c.Stderr = os.Stderr94 log.Printf("Running: %v...", c.Args)95 if err := c.Run(); err != nil {96 return errors.Wrap(err, "artifact download start")97 }98 c = exec.CommandContext(ctx, b.path, "delete")99 log.Printf("Running: %v...", c.Args)100 if err := c.Run(); err != nil {101 return errors.Wrap(err, "artifact download delete")102 }103 }104 return nil105}106// timeMinikubeStart returns the time it takes to execute `minikube start`107func timeMinikubeStart(ctx context.Context, binary *Binary, driver string, runtime string) (*result, error) {108 startCmd := exec.CommandContext(ctx, binary.path, "start", fmt.Sprintf("--driver=%s", driver), fmt.Sprintf("--container-runtime=%s", runtime))109 startCmd.Stderr = os.Stderr110 r, err := timeCommandLogs(startCmd)111 if err != nil {112 return nil, errors.Wrapf(err, "timing cmd: %v", startCmd.Args)113 }114 return r, nil115}116// timeEnableIngress returns the time it takes to execute `minikube addons enable ingress`117// It deletes the VM after `minikube addons enable ingress`.118func timeEnableIngress(ctx context.Context, binary *Binary) (*result, error) {119 enableCmd := exec.CommandContext(ctx, binary.path, "addons", "enable", "ingress")120 enableCmd.Stderr = os.Stderr121 r, err := timeCommandLogs(enableCmd)122 if err != nil {123 return nil, errors.Wrapf(err, "timing cmd: %v", enableCmd.Args)124 }125 return r, nil126}127// Ingress doesn't currently work on MacOS with the docker driver128func skipIngress(driver string) bool {129 return (runtime.GOOS == "darwin" && driver == "docker")130}131// We only want to run the tests if:132// 1. It's a VM driver and docker container runtime133// 2. It's docker driver with any container runtime134func proceed(driver string, runtime string) bool {135 return runtime == "docker" || driver == "docker"136}...

Full Screen

Full Screen

DownloadArtifacts

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 coreClient, err := taskagent.NewClient(context.Background(), connection)4 if err != nil {5 fmt.Println(err)6 os.Exit(-1)7 }8 testsClient, err := taskagent.NewClient(context.Background(), connection)9 if err != nil {10 fmt.Println(err)11 os.Exit(-1)12 }13 artifactsClient, err := taskagent.NewClient(context.Background(), connection)14 if err != nil {15 fmt.Println(err)16 os.Exit(-1)17 }18 taskClient, err := taskagent.NewClient(context.Background(), connection)19 if err != nil {20 fmt.Println(err)21 os.Exit(-1)22 }23 projectsClient, err := webapi.NewClient(context.Background(), connection)24 if err != nil {25 fmt.Println(err)26 os.Exit(-1)27 }28 buildClient, err := taskagent.NewClient(context.Background(), connection)29 if err != nil {30 fmt.Println(err)31 os.Exit(-1)32 }33 releaseClient, err := taskagent.NewClient(context.Background(), connection)34 if err != nil {35 fmt.Println(err)36 os.Exit(-1)37 }38 testClient, err := taskagent.NewClient(context.Background(), connection)39 if err != nil {40 fmt.Println(err)41 os.Exit(-1)42 }

Full Screen

Full Screen

DownloadArtifacts

Using AI Code Generation

copy

Full Screen

1import (2func getPatConnection(patToken string) (*azuredevops.Connection, error) {3}4func getBearerConnection(personalAccessToken string) (*azuredevops.Connection, error) {5}6func main() {7 pat := flag.String("pat", "", "Personal Access Token for Azure DevOps")8 flag.Parse()9 connection, err := getPatConnection(*pat)10 if err != nil {11 fmt.Println("Error creating connection:", err)12 os.Exit(1)13 }14 coreClient, err := core.NewClient(ctx, connection)15 if err != nil {16 fmt.Println("Error creating core client:", err)17 os.Exit(1)18 }19 testClient, err := test.NewClient(ctx, connection)20 if err != nil {21 fmt.Println("Error creating test client:", err)22 os.Exit(1)23 }24 webApiClient, err := webapi.NewClient(ctx, connection)25 if err != nil {26 fmt.Println("Error creating webapi client:", err)27 os.Exit(1)28 }29 user, err := coreClient.GetConnectedUserInfo(ctx, core.GetConnectedUserInfoArgs{})30 if err != nil {31 fmt.Println("Error

Full Screen

Full Screen

DownloadArtifacts

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 tests := autotest.Tests{4 }5 if err := tests.DownloadArtifacts("12345678-1234-5678-1234-567812345678"); err != nil {6 fmt.Println(err)7 }8}

Full Screen

Full Screen

DownloadArtifacts

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test := nuget.tests.Test{}4 test.DownloadArtifacts()5 fmt.Println("Done")6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful