How to use GetNewestExecutions method of result Package

Best Testkube code snippet using result.GetNewestExecutions

executions.go

Source:executions.go Github

copy

Full Screen

1package v12import (3 "bufio"4 "context"5 "encoding/json"6 "fmt"7 "net/http"8 "net/url"9 "os"10 "strconv"11 "github.com/gofiber/fiber/v2"12 "github.com/gofiber/websocket/v2"13 "github.com/valyala/fasthttp"14 "go.mongodb.org/mongo-driver/mongo"15 "k8s.io/apimachinery/pkg/api/errors"16 testsv3 "github.com/kubeshop/testkube-operator/apis/tests/v3"17 "github.com/kubeshop/testkube/internal/common"18 "github.com/kubeshop/testkube/internal/pkg/api/repository/result"19 "github.com/kubeshop/testkube/pkg/api/v1/testkube"20 "github.com/kubeshop/testkube/pkg/executor/client"21 "github.com/kubeshop/testkube/pkg/executor/output"22 testsmapper "github.com/kubeshop/testkube/pkg/mapper/tests"23 "github.com/kubeshop/testkube/pkg/secret"24 "github.com/kubeshop/testkube/pkg/types"25 "github.com/kubeshop/testkube/pkg/workerpool"26)27const (28 // defaultConcurrencyLevel is a default concurrency level for worker pool29 defaultConcurrencyLevel = "10"30 // latestExecutionNo defines the number of relevant latest executions31 latestExecutions = 532)33// ExecuteTestsHandler calls particular executor based on execution request content and type34func (s TestkubeAPI) ExecuteTestsHandler() fiber.Handler {35 return func(c *fiber.Ctx) error {36 ctx := c.Context()37 var request testkube.ExecutionRequest38 err := c.BodyParser(&request)39 if err != nil {40 return s.Error(c, http.StatusBadRequest, fmt.Errorf("test request body invalid: %w", err))41 }42 id := c.Params("id")43 var tests []testsv3.Test44 if id != "" {45 test, err := s.TestsClient.Get(id)46 if err != nil {47 return s.Error(c, http.StatusInternalServerError, fmt.Errorf("can't get test: %w", err))48 }49 tests = append(tests, *test)50 } else {51 testList, err := s.TestsClient.List(c.Query("selector"))52 if err != nil {53 return s.Error(c, http.StatusInternalServerError, fmt.Errorf("can't get tests: %w", err))54 }55 tests = append(tests, testList.Items...)56 }57 var results []testkube.Execution58 if len(tests) != 0 {59 concurrencyLevel, err := strconv.Atoi(c.Query("concurrency", defaultConcurrencyLevel))60 if err != nil {61 return s.Error(c, http.StatusBadRequest, fmt.Errorf("can't detect concurrency level: %w", err))62 }63 workerpoolService := workerpool.New[testkube.Test, testkube.ExecutionRequest, testkube.Execution](concurrencyLevel)64 go workerpoolService.SendRequests(s.prepareTestRequests(tests, request))65 go workerpoolService.Run(ctx)66 for r := range workerpoolService.GetResponses() {67 results = append(results, r.Result)68 }69 }70 if id != "" && len(results) != 0 {71 if results[0].ExecutionResult.IsFailed() {72 return s.Error(c, http.StatusInternalServerError, fmt.Errorf(results[0].ExecutionResult.ErrorMessage))73 }74 c.Status(http.StatusCreated)75 return c.JSON(results[0])76 }77 c.Status(http.StatusCreated)78 return c.JSON(results)79 }80}81func (s TestkubeAPI) prepareTestRequests(work []testsv3.Test, request testkube.ExecutionRequest) []workerpool.Request[82 testkube.Test, testkube.ExecutionRequest, testkube.Execution] {83 requests := make([]workerpool.Request[testkube.Test, testkube.ExecutionRequest, testkube.Execution], len(work))84 for i := range work {85 requests[i] = workerpool.Request[testkube.Test, testkube.ExecutionRequest, testkube.Execution]{86 Object: testsmapper.MapTestCRToAPI(work[i]),87 Options: request,88 ExecFn: s.executeTest,89 }90 }91 return requests92}93func (s TestkubeAPI) executeTest(ctx context.Context, test testkube.Test, request testkube.ExecutionRequest) (94 execution testkube.Execution, err error) {95 // generate random execution name in case there is no one set96 // like for docker images97 if request.Name == "" && test.ExecutionRequest != nil && test.ExecutionRequest.Name != "" {98 request.Name = test.ExecutionRequest.Name99 }100 if request.Name == "" {101 request.Name = test.Name102 }103 request.Number = s.getNextExecutionNumber(test.Name)104 request.Name = fmt.Sprintf("%s-%d", request.Name, request.Number)105 // test name + test execution name should be unique106 execution, _ = s.ExecutionResults.GetByNameAndTest(ctx, request.Name, test.Name)107 if execution.Name == request.Name {108 return execution.Err(fmt.Errorf("test execution with name %s already exists", request.Name)), nil109 }110 secretUUID, err := s.TestsClient.GetCurrentSecretUUID(test.Name)111 if err != nil {112 return execution.Errw("can't get current secret uuid: %w", err), nil113 }114 request.TestSecretUUID = secretUUID115 // merge available data into execution options test spec, executor spec, request, test id116 options, err := s.GetExecuteOptions(test.Namespace, test.Name, request)117 if err != nil {118 return execution.Errw("can't create valid execution options: %w", err), nil119 }120 // store execution in storage, can be get from API now121 execution = newExecutionFromExecutionOptions(options)122 options.ID = execution.Id123 if err := s.createSecretsReferences(&execution); err != nil {124 return execution.Errw("can't create secret variables `Secret` references: %w", err), nil125 }126 err = s.ExecutionResults.Insert(ctx, execution)127 if err != nil {128 return execution.Errw("can't create new test execution, can't insert into storage: %w", err), nil129 }130 s.Log.Infow("calling executor with options", "options", options.Request)131 execution.Start()132 s.Events.Notify(testkube.NewEventStartTest(&execution))133 // update storage with current execution status134 err = s.ExecutionResults.StartExecution(ctx, execution.Id, execution.StartTime)135 if err != nil {136 s.Events.Notify(testkube.NewEventEndTestFailed(&execution))137 return execution.Errw("can't execute test, can't insert into storage error: %w", err), nil138 }139 options.HasSecrets = true140 if _, err = s.SecretClient.Get(secret.GetMetadataName(execution.TestName)); err != nil {141 if !errors.IsNotFound(err) {142 s.Events.Notify(testkube.NewEventEndTestFailed(&execution))143 return execution.Errw("can't get secrets: %w", err), nil144 }145 options.HasSecrets = false146 }147 var result testkube.ExecutionResult148 // sync/async test execution149 if options.Sync {150 result, err = s.Executor.ExecuteSync(&execution, options)151 } else {152 result, err = s.Executor.Execute(&execution, options)153 }154 // set execution result to one created155 execution.ExecutionResult = &result156 // update storage with current execution status157 if uerr := s.ExecutionResults.UpdateResult(ctx, execution.Id, result); uerr != nil {158 s.Events.Notify(testkube.NewEventEndTestFailed(&execution))159 return execution.Errw("update execution error: %w", uerr), nil160 }161 if err != nil {162 s.Events.Notify(testkube.NewEventEndTestFailed(&execution))163 return execution.Errw("test execution failed: %w", err), nil164 }165 s.Log.Infow("test started", "executionId", execution.Id, "status", execution.ExecutionResult.Status)166 // notify immediately onlly when sync run otherwise job results handler need notify about test finish167 if options.Sync && execution.ExecutionResult != nil && *execution.ExecutionResult.Status != testkube.RUNNING_ExecutionStatus {168 s.Events.Notify(testkube.NewEventEndTestSuccess(&execution))169 }170 return execution, nil171}172// createSecretsReferences strips secrets from text and store it inside model as reference to secret173func (s TestkubeAPI) createSecretsReferences(execution *testkube.Execution) (err error) {174 secrets := map[string]string{}175 secretName := execution.Id + "-vars"176 for k, v := range execution.Variables {177 if v.IsSecret() {178 obfuscated := execution.Variables[k]179 if v.SecretRef != nil {180 obfuscated.SecretRef = &testkube.SecretRef{181 Namespace: execution.TestNamespace,182 Name: v.SecretRef.Name,183 Key: v.SecretRef.Key,184 }185 } else {186 obfuscated.Value = ""187 obfuscated.SecretRef = &testkube.SecretRef{188 Namespace: execution.TestNamespace,189 Name: secretName,190 Key: v.Name,191 }192 secrets[v.Name] = v.Value193 }194 execution.Variables[k] = obfuscated195 }196 }197 labels := map[string]string{"executionID": execution.Id, "testName": execution.TestName}198 if len(secrets) > 0 {199 return s.SecretClient.Create(200 secretName,201 labels,202 secrets,203 )204 }205 return nil206}207// ListExecutionsHandler returns array of available test executions208func (s TestkubeAPI) ListExecutionsHandler() fiber.Handler {209 return func(c *fiber.Ctx) error {210 // TODO refactor into some Services (based on some abstraction for CRDs at least / CRUD)211 // should we split this to separate endpoint? currently this one handles212 // endpoints from /executions and from /tests/{id}/executions213 // or should id be a query string as it's some kind of filter?214 filter := getFilterFromRequest(c)215 executions, err := s.ExecutionResults.GetExecutions(c.Context(), filter)216 if err != nil {217 return s.Error(c, http.StatusInternalServerError, err)218 }219 executionTotals, err := s.ExecutionResults.GetExecutionTotals(c.Context(), false, filter)220 if err != nil {221 return s.Error(c, http.StatusInternalServerError, err)222 }223 filteredTotals, err := s.ExecutionResults.GetExecutionTotals(c.Context(), true, filter)224 if err != nil {225 return s.Error(c, http.StatusInternalServerError, err)226 }227 results := testkube.ExecutionsResult{228 Totals: &executionTotals,229 Filtered: &filteredTotals,230 Results: mapExecutionsToExecutionSummary(executions),231 }232 return c.JSON(results)233 }234}235func (s TestkubeAPI) ExecutionLogsStreamHandler() fiber.Handler {236 return websocket.New(func(c *websocket.Conn) {237 executionID := c.Params("executionID")238 l := s.Log.With("executionID", executionID)239 l.Debugw("getting pod logs and passing to websocket", "id", c.Params("id"), "locals", c.Locals, "remoteAddr", c.RemoteAddr(), "localAddr", c.LocalAddr())240 logs, err := s.Executor.Logs(executionID)241 if err != nil {242 l.Errorw("can't get pod logs", "error", err)243 c.Conn.Close()244 return245 }246 for logLine := range logs {247 l.Debugw("sending log line to websocket", "line", logLine)248 c.WriteJSON(logLine)249 }250 })251}252// ExecutionLogsHandler streams the logs from a test execution253func (s *TestkubeAPI) ExecutionLogsHandler() fiber.Handler {254 return func(c *fiber.Ctx) error {255 executionID := c.Params("executionID")256 s.Log.Debug("getting logs", "executionID", executionID)257 ctx := c.Context()258 ctx.SetContentType("text/event-stream")259 ctx.Response.Header.Set("Cache-Control", "no-cache")260 ctx.Response.Header.Set("Connection", "keep-alive")261 ctx.Response.Header.Set("Transfer-Encoding", "chunked")262 ctx.SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {263 s.Log.Debug("starting stream writer")264 w.Flush()265 execution, err := s.ExecutionResults.Get(ctx, executionID)266 if err != nil {267 output.PrintError(os.Stdout, fmt.Errorf("could not get execution result for ID %s: %w", executionID, err))268 s.Log.Errorw("getting execution error", "error", err)269 w.Flush()270 return271 }272 if execution.ExecutionResult.IsCompleted() {273 err := s.streamLogsFromResult(execution.ExecutionResult, w)274 if err != nil {275 output.PrintError(os.Stdout, fmt.Errorf("could not get execution result for ID %s: %w", executionID, err))276 s.Log.Errorw("getting execution error", "error", err)277 w.Flush()278 }279 return280 }281 s.streamLogsFromJob(executionID, w)282 }))283 return nil284 }285}286// GetExecutionHandler returns test execution object for given test and execution id/name287func (s TestkubeAPI) GetExecutionHandler() fiber.Handler {288 return func(c *fiber.Ctx) error {289 ctx := c.Context()290 id := c.Params("id", "")291 executionID := c.Params("executionID")292 var execution testkube.Execution293 var err error294 if id == "" {295 execution, err = s.ExecutionResults.Get(ctx, executionID)296 if err == mongo.ErrNoDocuments {297 execution, err = s.ExecutionResults.GetByName(ctx, executionID)298 if err == mongo.ErrNoDocuments {299 return s.Error(c, http.StatusNotFound, fmt.Errorf("test with execution id/name %s not found", executionID))300 }301 }302 if err != nil {303 return s.Error(c, http.StatusInternalServerError, err)304 }305 } else {306 execution, err = s.ExecutionResults.GetByNameAndTest(ctx, executionID, id)307 if err == mongo.ErrNoDocuments {308 return s.Error(c, http.StatusNotFound, fmt.Errorf("test %s/%s not found", id, executionID))309 }310 if err != nil {311 return s.Error(c, http.StatusInternalServerError, err)312 }313 }314 execution.Duration = types.FormatDuration(execution.Duration)315 testSecretMap := make(map[string]string)316 if execution.TestSecretUUID != "" {317 testSecretMap, err = s.TestsClient.GetSecretTestVars(execution.TestName, execution.TestSecretUUID)318 if err != nil {319 return s.Error(c, http.StatusInternalServerError, err)320 }321 }322 testSuiteSecretMap := make(map[string]string)323 if execution.TestSuiteSecretUUID != "" {324 testSuiteSecretMap, err = s.TestsSuitesClient.GetSecretTestSuiteVars(execution.TestSuiteName, execution.TestSuiteSecretUUID)325 if err != nil {326 return s.Error(c, http.StatusInternalServerError, err)327 }328 }329 for key, value := range testSuiteSecretMap {330 testSecretMap[key] = value331 }332 for key, value := range testSecretMap {333 if variable, ok := execution.Variables[key]; ok && value != "" {334 variable.Value = string(value)335 variable.SecretRef = nil336 execution.Variables[key] = variable337 }338 }339 s.Log.Debugw("get test execution request - debug", "execution", execution)340 return c.JSON(execution)341 }342}343func (s TestkubeAPI) AbortExecutionHandler() fiber.Handler {344 return func(c *fiber.Ctx) error {345 ctx := c.Context()346 executionID := c.Params("executionID")347 execution, err := s.ExecutionResults.Get(ctx, executionID)348 if err == mongo.ErrNoDocuments {349 return s.Error(c, http.StatusNotFound, fmt.Errorf("test with execution id %s not found", executionID))350 }351 if err != nil {352 return s.Error(c, http.StatusInternalServerError, err)353 }354 result := s.Executor.Abort(executionID)355 s.Metrics.IncAbortTest(execution.TestType, result.IsFailed())356 return err357 }358}359func (s TestkubeAPI) GetArtifactHandler() fiber.Handler {360 return func(c *fiber.Ctx) error {361 executionID := c.Params("executionID")362 fileName := c.Params("filename")363 // TODO fix this someday :) we don't know 15 mins before release why it's working this way364 // remember about CLI client and Dashboard client too!365 unescaped, err := url.QueryUnescape(fileName)366 if err == nil {367 fileName = unescaped368 }369 unescaped, err = url.QueryUnescape(fileName)370 if err == nil {371 fileName = unescaped372 }373 //// quickfix end374 file, err := s.Storage.DownloadFile(executionID, fileName)375 if err != nil {376 return s.Error(c, http.StatusInternalServerError, err)377 }378 defer file.Close()379 return c.SendStream(file)380 }381}382// GetArtifacts returns list of files in the given bucket383func (s TestkubeAPI) ListArtifactsHandler() fiber.Handler {384 return func(c *fiber.Ctx) error {385 executionID := c.Params("executionID")386 files, err := s.Storage.ListFiles(executionID)387 if err != nil {388 return s.Error(c, http.StatusInternalServerError, err)389 }390 return c.JSON(files)391 }392}393func (s TestkubeAPI) GetExecuteOptions(namespace, id string, request testkube.ExecutionRequest) (options client.ExecuteOptions, err error) {394 // get test content from kubernetes CRs395 testCR, err := s.TestsClient.Get(id)396 if err != nil {397 return options, fmt.Errorf("can't get test custom resource %w", err)398 }399 test := testsmapper.MapTestCRToAPI(*testCR)400 if test.ExecutionRequest != nil {401 // Test variables lowest priority, then test suite, then test suite execution / test execution402 request.Variables = mergeVariables(test.ExecutionRequest.Variables, request.Variables)403 // Combine test executor args with execution args404 request.Args = append(request.Args, test.ExecutionRequest.Args...)405 request.Envs = mergeEnvs(request.Envs, test.ExecutionRequest.Envs)406 request.SecretEnvs = mergeEnvs(request.SecretEnvs, test.ExecutionRequest.SecretEnvs)407 if request.VariablesFile == "" && test.ExecutionRequest.VariablesFile != "" {408 request.VariablesFile = test.ExecutionRequest.VariablesFile409 }410 if request.HttpProxy == "" && test.ExecutionRequest.HttpProxy != "" {411 request.HttpProxy = test.ExecutionRequest.HttpProxy412 }413 if request.HttpsProxy == "" && test.ExecutionRequest.HttpsProxy != "" {414 request.HttpsProxy = test.ExecutionRequest.HttpsProxy415 }416 }417 // get executor from kubernetes CRs418 executorCR, err := s.ExecutorsClient.GetByType(testCR.Spec.Type_)419 if err != nil {420 return options, fmt.Errorf("can't get executor spec: %w", err)421 }422 var usernameSecret, tokenSecret *testkube.SecretRef423 if test.Content != nil && test.Content.Repository != nil {424 usernameSecret = test.Content.Repository.UsernameSecret425 tokenSecret = test.Content.Repository.TokenSecret426 }427 return client.ExecuteOptions{428 TestName: id,429 Namespace: namespace,430 TestSpec: testCR.Spec,431 ExecutorName: executorCR.ObjectMeta.Name,432 ExecutorSpec: executorCR.Spec,433 Request: request,434 Sync: request.Sync,435 Labels: testCR.Labels,436 UsernameSecret: usernameSecret,437 TokenSecret: tokenSecret,438 ImageOverride: request.Image,439 }, nil440}441// streamLogsFromResult writes logs from the output of executionResult to the writer442func (s *TestkubeAPI) streamLogsFromResult(executionResult *testkube.ExecutionResult, w *bufio.Writer) error {443 enc := json.NewEncoder(w)444 fmt.Fprintf(w, "data: ")445 s.Log.Debug("using logs from result")446 output := testkube.ExecutorOutput{447 Type_: output.TypeResult,448 Content: executionResult.Output,449 Result: executionResult,450 }451 err := enc.Encode(output)452 if err != nil {453 s.Log.Infow("Encode", "error", err)454 return err455 }456 fmt.Fprintf(w, "\n")457 w.Flush()458 return nil459}460// streamLogsFromJob streams logs in chunks to writer from the running execution461func (s *TestkubeAPI) streamLogsFromJob(executionID string, w *bufio.Writer) {462 enc := json.NewEncoder(w)463 s.Log.Debug("getting logs from Kubernetes job")464 logs, err := s.Executor.Logs(executionID)465 s.Log.Debugw("waiting for jobs channel", "channelSize", len(logs))466 if err != nil {467 output.PrintError(os.Stdout, err)468 s.Log.Errorw("getting logs error", "error", err)469 w.Flush()470 return471 }472 // loop through pods log lines - it's blocking channel473 // and pass single log output as sse data chunk474 for out := range logs {475 s.Log.Debugw("got log", "out", out)476 fmt.Fprintf(w, "data: ")477 err = enc.Encode(out)478 if err != nil {479 s.Log.Infow("Encode", "error", err)480 }481 // enc.Encode adds \n and we need \n\n after `data: {}` chunk482 fmt.Fprintf(w, "\n")483 w.Flush()484 }485}486func (s TestkubeAPI) getNextExecutionNumber(testName string) int {487 number, err := s.ExecutionResults.GetNextExecutionNumber(context.Background(), testName)488 if err != nil {489 s.Log.Errorw("retrieving latest execution", "error", err)490 return number491 }492 return number493}494func mergeVariables(vars1 map[string]testkube.Variable, vars2 map[string]testkube.Variable) map[string]testkube.Variable {495 variables := map[string]testkube.Variable{}496 for k, v := range vars1 {497 variables[k] = v498 }499 for k, v := range vars2 {500 variables[k] = v501 }502 return variables503}504func mergeEnvs(envs1 map[string]string, envs2 map[string]string) map[string]string {505 envs := map[string]string{}506 for k, v := range envs1 {507 envs[k] = v508 }509 for k, v := range envs2 {510 envs[k] = v511 }512 return envs513}514func newExecutionFromExecutionOptions(options client.ExecuteOptions) testkube.Execution {515 execution := testkube.NewExecution(516 options.Namespace,517 options.TestName,518 options.Request.TestSuiteName,519 options.Request.Name,520 options.TestSpec.Type_,521 options.Request.Number,522 testsmapper.MapTestContentFromSpec(options.TestSpec.Content),523 testkube.NewRunningExecutionResult(),524 options.Request.Variables,525 options.Request.TestSecretUUID,526 options.Request.TestSuiteSecretUUID,527 common.MergeMaps(options.Labels, options.Request.ExecutionLabels),528 )529 execution.Envs = options.Request.Envs530 execution.Args = options.Request.Args531 execution.VariablesFile = options.Request.VariablesFile532 return execution533}534func mapExecutionsToExecutionSummary(executions []testkube.Execution) []testkube.ExecutionSummary {535 result := make([]testkube.ExecutionSummary, len(executions))536 for i, execution := range executions {537 result[i] = testkube.ExecutionSummary{538 Id: execution.Id,539 Name: execution.Name,540 Number: execution.Number,541 TestName: execution.TestName,542 TestType: execution.TestType,543 Status: execution.ExecutionResult.Status,544 StartTime: execution.StartTime,545 EndTime: execution.EndTime,546 Duration: types.FormatDuration(execution.Duration),547 DurationMs: types.FormatDurationMs(execution.Duration),548 Labels: execution.Labels,549 }550 }551 return result552}553// GetLatestExecutionLogs returns the latest executions' logs554func (s *TestkubeAPI) GetLatestExecutionLogs(c context.Context) (map[string][]string, error) {555 latestExecutions, err := s.getNewestExecutions(c)556 if err != nil {557 return nil, fmt.Errorf("could not list executions: %w", err)558 }559 executionLogs := map[string][]string{}560 for _, e := range latestExecutions {561 logs, err := s.getExecutionLogs(e)562 if err != nil {563 return nil, fmt.Errorf("could not get logs: %w", err)564 }565 executionLogs[e.Id] = logs566 }567 return executionLogs, nil568}569// getNewestExecutions returns the latest Testkube executions570func (s *TestkubeAPI) getNewestExecutions(c context.Context) ([]testkube.Execution, error) {571 f := result.NewExecutionsFilter().WithPage(1).WithPageSize(latestExecutions)572 executions, err := s.ExecutionResults.GetExecutions(c, f)573 if err != nil {574 return []testkube.Execution{}, fmt.Errorf("could not get executions from repo: %w", err)575 }576 return executions, nil577}578// getExecutionLogs returns logs from an execution579func (s *TestkubeAPI) getExecutionLogs(execution testkube.Execution) ([]string, error) {580 result := []string{}581 if execution.ExecutionResult.IsCompleted() {582 return append(result, execution.ExecutionResult.Output), nil583 }584 logs, err := s.Executor.Logs(execution.Id)585 if err != nil {586 return []string{}, fmt.Errorf("could not get logs for execution %s: %w", execution.Id, err)587 }588 for out := range logs {589 result = append(result, out.Result.Output)590 }591 return result, nil592}...

Full Screen

Full Screen

mongo.go

Source:mongo.go Github

copy

Full Screen

...77 return nil, err78 }79 return executions, nil80}81func (r *MongoRepository) GetNewestExecutions(ctx context.Context, limit int) (result []testkube.TestSuiteExecution, err error) {82 result = make([]testkube.TestSuiteExecution, 0)83 resultLimit := int64(limit)84 opts := &options.FindOptions{Limit: &resultLimit}85 opts.SetSort(bson.D{{Key: "_id", Value: -1}})86 cursor, err := r.Coll.Find(ctx, bson.M{}, opts)87 if err != nil {88 return result, err89 }90 err = cursor.All(ctx, &result)91 return92}93func (r *MongoRepository) GetExecutionsTotals(ctx context.Context, filter ...Filter) (totals testkube.ExecutionsTotals, err error) {94 var result []struct {95 Status string `bson:"_id"`...

Full Screen

Full Screen

GetNewestExecutions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 opts = append(opts, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")))4 conn, err := grpc.Dial("localhost:8080", opts...)5 if err != nil {6 log.Fatalf("fail to dial: %v", err)7 }8 defer conn.Close()9 c := pb.NewResultsClient(conn)10 ctx := context.Background()11 r, err := c.GetNewestExecutions(ctx, &pb.GetNewestExecutionsRequest{ProjectId: "test-project", PageSize: 2})12 if err != nil {13 log.Fatalf("could not greet: %v", err)14 }15 fmt.Println(r)16}17import (18func main() {19 opts = append(opts, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")))20 conn, err := grpc.Dial("localhost:8080", opts...)21 if err != nil {22 log.Fatalf("fail to dial: %v", err)23 }24 defer conn.Close()25 c := pb.NewResultsClient(conn)26 ctx := context.Background()27 r, err := c.GetNewestExecutions(ctx, &pb.GetNewestExecutionsRequest{ProjectId: "test-project", PageSize: 3})28 if err != nil {29 log.Fatalf("could not greet: %v", err)30 }31 fmt.Println(r)32}33import (

Full Screen

Full Screen

GetNewestExecutions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 opts := []selenium.ServiceOption{}4 selenium.SetDebug(true)5 service, err := selenium.NewChromeDriverService("chromedriver", 9515, opts...)6 if err != nil {7 }8 defer service.Stop()9 caps := selenium.Capabilities{"browserName": "chrome"}10 caps.AddChrome(chrome.Capabilities{11 Args: []string{12 },13 })

Full Screen

Full Screen

GetNewestExecutions

Using AI Code Generation

copy

Full Screen

1result := client.GetNewestExecutions(ctx, "project1", "workflow1", 5)2fmt.Println(result)3result := client.GetWorkflowExecutions(ctx, "project1", "workflow1", 5, 5, 5)4fmt.Println(result)5result := client.GetWorkflowExecution(ctx, "project1", "workflow1", "execution1")6fmt.Println(result)7result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)8fmt.Println(result)9result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)10fmt.Println(result)11result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)12fmt.Println(result)13result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)14fmt.Println(result)15result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)16fmt.Println(result)17result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)18fmt.Println(result)19result := client.GetWorkflowExecutionLogs(ctx, "project1", "workflow1", "execution1", 5, 5)20fmt.Println(result)

Full Screen

Full Screen

GetNewestExecutions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := result.NewResult()4 newestExecutions := r.GetNewestExecutions(10)5 fmt.Println(newestExecutions)6}7import (8type Result struct {9}10func NewResult() *Result {11 return &Result{12 executions: []Execution{},13 }14}15func (r *Result) AddExecution(execution Execution) {16 r.executions = append(r.executions, execution)17}18func (r *Result) GetNewestExecutions(count int) []Execution {19 sort.Slice(r.executions, func(i, j int) bool {20 return r.executions[i].Time.After(r.executions[j].Time)21 })22}23func (r *Result) Print() {24 for _, execution := range r.executions {25 fmt.Println(execution)26 }27}28type Execution struct {29}30func (e Execution) String() string {31 return fmt.Sprintf("%v %v %v", e.Time, e.Name, e.Result)32}33func (t Time) String() string {34 return time.Time(t).Format("2006-01-02 15:04:05")35}36func (t *Time) UnmarshalJSON(b []byte) error {37 if string(b) == "null" {38 }

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