Skip to content

Commit

Permalink
chore: log concurrent ID when running examples (#200)
Browse files Browse the repository at this point in the history
- this makes it easier to work out which log line relates to which
example
- also logs a summary at the end

[#177317568](https://www.pivotaltracker.com/story/show/177317568)
  • Loading branch information
blgm authored Mar 12, 2021
1 parent 461595d commit 10a0303
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 130 deletions.
15 changes: 6 additions & 9 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,14 @@ user-defined plans.
log.Fatalf("Error creating client: %v", err)
}

if exampleName != "" && serviceName == "" {
switch {
case exampleName != "" && serviceName == "":
log.Fatalf("If an example name is specified, you must provide an accompanying service name.")
} else if fileName != "" {
if err := client.RunExamplesFromFile(apiClient, fileName, serviceName, exampleName); err != nil {
log.Fatalf("Error executing examples from file: %v", err)
}
} else if err := client.RunExamplesForService(server.GetExamplesFromServer(), apiClient, serviceName, exampleName, exampleJobCount); err != nil {
log.Fatalf("Error executing examples: %v", err)
case fileName != "":
client.RunExamplesFromFile(apiClient, fileName, serviceName, exampleName)
default:
client.RunExamplesForService(server.GetExamplesFromServer(), apiClient, serviceName, exampleName, exampleJobCount)
}

log.Println("Success")
},
}

Expand Down
6 changes: 1 addition & 5 deletions cmd/pak.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ dependencies, services it provides, and the contents.
Short: "run the examples from a brokerpak",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := brokerpak.RunExamples(args[0]); err != nil {
log.Fatalf("Error executing examples: %v", err)
}

log.Println("Success")
brokerpak.RunExamples(args[0])
},
})

Expand Down
11 changes: 6 additions & 5 deletions pkg/brokerpak/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package brokerpak
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"text/tabwriter"
Expand Down Expand Up @@ -173,23 +174,23 @@ func RegisterAll(registry broker.BrokerRegistry) error {
}

// RunExamples executes the examples from a brokerpak.
func RunExamples(pack string) error {
func RunExamples(pack string) {
registry, err := registryFromLocalBrokerpak(pack)
if err != nil {
return err
log.Fatalf("Error executing examples (registry): %v", err)
}

apiClient, err := client.NewClientFromEnv()
if err != nil {
return err
log.Fatalf("Error executing examples (client): %v", err)
}

allExamples, err := server.GetAllCompleteServiceExamples(registry)
if err != nil {
return err
log.Fatalf("Error executing examples (getting): %v", err)
}

return client.RunExamplesForService(allExamples, apiClient, "", "", 1)
client.RunExamplesForService(allExamples, apiClient, "", "", 1)
}

// Docs generates the markdown usage docs for the given pack and writes them to stdout.
Expand Down
Loading

0 comments on commit 10a0303

Please sign in to comment.