| // Copyright 2019 The Fuchsia 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 main |
| |
| import ( |
| "context" |
| "flag" |
| "fmt" |
| "log" |
| "os" |
| |
| "fuchsia.googlesource.com/infra/infra/resultstore" |
| "github.com/google/uuid" |
| ) |
| |
| var ( |
| // Google Cloud Project ID to associate the invocation with. |
| projectID string |
| ) |
| |
| func usage() { |
| fmt.Fprintf(os.Stderr, ` |
| example [flags] |
| |
| Creates an example invocation in resultstore. This is really an integration test for |
| //infra/infra/resultstore, which is only meant to be run locally. |
| |
| Options: |
| `) |
| |
| flag.PrintDefaults() |
| } |
| |
| func init() { |
| flag.Usage = usage |
| flag.StringVar(&projectID, "project-id", "", "Google Cloud Project ID to associate the invocation with") |
| } |
| |
| func main() { |
| flag.Parse() |
| if flag.NArg() != 0 { |
| flag.Usage() |
| return |
| } |
| |
| if projectID == "" { |
| log.Fatal("missing project-id") |
| } |
| |
| ctx, err := resultstore.SetAuthToken(context.Background(), uuid.New().String()) |
| if err != nil { |
| log.Fatal(err) |
| } |
| |
| if err := execute(ctx); err != nil { |
| log.Fatal(err) |
| } |
| } |
| |
| func execute(ctx context.Context) error { |
| client, err := resultstore.Connect(ctx, resultstore.Staging) |
| if err != nil { |
| return err |
| } |
| |
| simulator, err := NewSimulator(ctx, client, projectID, "test_configuration_id", 123456789) |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("created invocation at: %s", simulator.InvocationURL()) |
| |
| finalStatus := resultstore.Passed |
| tests := []string{ |
| "foo", |
| "bar", |
| "baz", |
| "bang", |
| "fizz", |
| "snap", |
| "crackle", |
| "pop", |
| "wee", |
| "waa", |
| "zimmy", |
| "wam", |
| "wuzzle", |
| } |
| for _, test := range tests { |
| status, err := simulator.Test(ctx, test) |
| if err != nil { |
| return err |
| } |
| if status == resultstore.Failed { |
| finalStatus = resultstore.Failed |
| } |
| } |
| |
| if err := simulator.End(ctx, finalStatus); err != nil { |
| return err |
| } |
| |
| return nil |
| } |