Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QT-644] Concurrently decode scenarios if possible #116

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func requireEqualOperationResponses(t *testing.T, expected *pb.OperationResponse
sortResponses(expectedResponses)
sortResponses(gotResponses)

for i := range expected.Responses {
for i := range expected.GetResponses() {
got := gotResponses[i]
expected := expectedResponses[i]

Expand Down
10 changes: 5 additions & 5 deletions acceptance/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func TestAcc_Cmd_Fmt(t *testing.T) {
got := &pb.FormatResponse{}
require.NoErrorf(t, protojson.Unmarshal(out, got), string(out))
require.Len(t, got.GetResponses(), len(expected.GetResponses()))
for i := range expected.Responses {
got := got.Responses[i]
expected := expected.Responses[i]
require.Equal(t, expected.Path, got.Path)
require.Equal(t, expected.Changed, got.Changed)
for i := range expected.GetResponses() {
got := got.GetResponses()[i]
expected := expected.GetResponses()[i]
require.Equal(t, expected.GetPath(), got.GetPath())
require.Equal(t, expected.GetChanged(), got.GetChanged())
}
}
4 changes: 2 additions & 2 deletions acceptance/scenario_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestAcc_Cmd_Scenario_Check(t *testing.T) {
},
}

expected.Responses = append(expected.Responses, &pb.Operation_Response{
expected.Responses = append(expected.GetResponses(), &pb.Operation_Response{
Op: &pb.Ref_Operation{
Scenario: scenarioRef,
},
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestAcc_Cmd_Scenario_Check_WithWarnings(t *testing.T) {
}
}

expected.Responses = append(expected.Responses, &pb.Operation_Response{
expected.Responses = append(expected.GetResponses(), &pb.Operation_Response{
Op: &pb.Ref_Operation{
Scenario: scenarioRef,
},
Expand Down
5 changes: 2 additions & 3 deletions acceptance/scenario_e2e_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hashicorp/enos/proto/hashicorp/enos/v1/pb"
Expand Down Expand Up @@ -98,7 +97,7 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
// Lets try one more time to destroy resources that might have been
// created
out, err := enos.run(context.Background(), fmt.Sprintf("scenario destroy --chdir %s --out %s", path, outDir))
assert.NoErrorf(t, err, string(out))
require.NoErrorf(t, err, string(out))
})

expected := &pb.OperationResponses{
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
},
}

expected.Responses = append(expected.Responses, res)
expected.Responses = append(expected.GetResponses(), res)
}

cmd := fmt.Sprintf("scenario run --chdir %s --out %s --format json", path, outDir)
Expand Down
4 changes: 2 additions & 2 deletions acceptance/scenario_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func TestAcc_Cmd_Scenario_List(t *testing.T) {
got := &pb.ListScenariosResponse{}
require.NoError(t, protojson.Unmarshal(out, got))
require.Len(t, got.GetScenarios(), len(test.out.GetScenarios()))
for i := range test.out.Scenarios {
require.Equal(t, test.out.Scenarios[i].String(), got.Scenarios[i].String())
for i := range test.out.GetScenarios() {
require.Equal(t, test.out.GetScenarios()[i].String(), got.GetScenarios()[i].String())
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions acceptance/scenario_sample_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestAcc_Cmd_Scenario_Sample_List(t *testing.T) {
got := &pb.ListSamplesResponse{}
require.NoError(t, protojson.Unmarshal(out, got))
require.Len(t, got.GetSamples(), len(test.out.GetSamples()))
for i := range test.out.Samples {
require.Equal(t, test.out.Samples[i].String(), got.Samples[i].String())
for i := range test.out.GetSamples() {
require.Equal(t, test.out.GetSamples()[i].String(), got.GetSamples()[i].String())
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/command/enos/cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func runFmtCmd(cmd *cobra.Command, args []string) error {
return nil
}

if fmtCfg.Recursive {
if fmtCfg.GetRecursive() {
err = filepath.Walk(path, readRawFiles)
} else {
err = readRawFiles(path, nil, nil)
Expand Down Expand Up @@ -148,7 +148,7 @@ func runFmtCmd(cmd *cobra.Command, args []string) error {

/// Scan STDIN for content if we've been told to use STDIN either implicitly
// of explicitly.
if (argP == "-" || argP == "") && len(req.Files) == 0 {
if (argP == "-" || argP == "") && len(req.GetFiles()) == 0 {
bytes, err := io.ReadAll(cmd.InOrStdin())
if err != nil {
res.Diagnostics = diagnostics.FromErr(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/command/enos/cmd/scenario_sample_observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func (t *sampleObserveFilter) Proto() *pb.Sample_Filter {
if i == 0 {
f.Subsets = []*pb.Sample_Subset_ID{}
}
f.Subsets = append(f.Subsets, &pb.Sample_Subset_ID{Name: t.OnlySubsets[i]})
f.Subsets = append(f.GetSubsets(), &pb.Sample_Subset_ID{Name: t.OnlySubsets[i]})
}

for i := range t.ExcludeSubsets {
if i == 0 {
f.ExcludeSubsets = []*pb.Sample_Subset_ID{}
}
f.ExcludeSubsets = append(f.ExcludeSubsets, &pb.Sample_Subset_ID{Name: t.ExcludeSubsets[i]})
f.ExcludeSubsets = append(f.GetExcludeSubsets(), &pb.Sample_Subset_ID{Name: t.ExcludeSubsets[i]})
}

return f
Expand Down
20 changes: 10 additions & 10 deletions internal/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func hasSeverity(sev pb.Diagnostic_Severity, diags ...[]*pb.Diagnostic) bool {
}

for _, diag := range combined {
if diag.Severity == sev {
if diag.GetSeverity() == sev {
return true
}
}
Expand Down Expand Up @@ -118,14 +118,14 @@ func FromTFJSON(in []tfjson.Diagnostic) []*pb.Diagnostic {
Filename: din.Range.Filename,
}

if d.Range.Start != nil {
if d.GetRange().GetStart() != nil {
d.Range.Start = &pb.Range_Pos{
Line: int64(din.Range.Start.Line),
Column: int64(din.Range.Start.Column),
Byte: int64(din.Range.Start.Byte),
}
}
if d.Range.End != nil {
if d.GetRange().GetEnd() != nil {
d.Range.End = &pb.Range_Pos{
Line: int64(din.Range.End.Line),
Column: int64(din.Range.End.Column),
Expand All @@ -150,7 +150,7 @@ func FromTFJSON(in []tfjson.Diagnostic) []*pb.Diagnostic {
if i == 0 {
d.Snippet.Values = []*pb.Diagnostic_ExpressionValue{}
}
d.Snippet.Values = append(d.Snippet.Values, &pb.Diagnostic_ExpressionValue{
d.Snippet.Values = append(d.GetSnippet().GetValues(), &pb.Diagnostic_ExpressionValue{
Traversal: expr.Traversal,
Statement: expr.Statement,
})
Expand Down Expand Up @@ -321,7 +321,7 @@ func FromHCL(files map[string]*hcl.File, diags hcl.Diagnostics) []*pb.Diagnostic
}
}
sort.Slice(values, func(i, j int) bool {
return values[i].Traversal < values[j].Traversal
return values[i].GetTraversal() < values[j].GetTraversal()
})
pbDiag.Snippet.Values = values
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func String(diag *pb.Diagnostic, opts ...StringOpt) string {
width = int(cfg.uiSettings.GetWidth())
}

switch diag.Severity {
switch diag.GetSeverity() {
case pb.Diagnostic_SEVERITY_ERROR:
buf.WriteString(cfg.color.Color("[bold][red]Error: [reset]"))
leftRuleLine = cfg.color.Color("[red]│[reset] ")
Expand All @@ -415,22 +415,22 @@ func String(diag *pb.Diagnostic, opts ...StringOpt) string {
// We don't wrap the summary, since we expect it to be terse, and since
// this is where we put the text of a native Go error it may not always
// be pure text that lends itself well to word-wrapping.
fmt.Fprintf(&buf, cfg.color.Color("[bold]%s[reset]\n\n"), diag.Summary)
fmt.Fprintf(&buf, cfg.color.Color("[bold]%s[reset]\n\n"), diag.GetSummary())

appendSourceSnippets(&buf, diag, cfg.color)

if diag.Detail != "" {
if diag.GetDetail() != "" {
paraWidth := width - leftRuleWidth - 1 // leave room for the left rule
if paraWidth > 0 {
lines := strings.Split(diag.Detail, "\n")
lines := strings.Split(diag.GetDetail(), "\n")
for _, line := range lines {
if !strings.HasPrefix(line, " ") {
line = wordwrap.WrapString(line, uint(paraWidth))
}
fmt.Fprintf(&buf, "%s\n", line)
}
} else {
fmt.Fprintf(&buf, "%s\n", diag.Detail)
fmt.Fprintf(&buf, "%s\n", diag.GetDetail())
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/flightplan/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func DecodeProto(

hclDiags := dec.Parse()
if len(hclDiags) > 0 {
res.Diagnostics = append(res.Diagnostics, diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
res.Diagnostics = append(res.GetDiagnostics(), diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
}

if diagnostics.HasErrors(res.GetDiagnostics()) {
Expand All @@ -441,7 +441,7 @@ func DecodeProto(

fp, hclDiags := dec.Decode(ctx)
if len(hclDiags) > 0 {
res.Diagnostics = append(res.Diagnostics, diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
res.Diagnostics = append(res.GetDiagnostics(), diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
}

return fp, res
Expand Down
8 changes: 4 additions & 4 deletions internal/flightplan/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (v *Vector) Proto() *pb.Matrix_Vector {
}

for _, elm := range v.elements {
pbv.Elements = append(pbv.Elements, &pb.Matrix_Element{
pbv.Elements = append(pbv.GetElements(), &pb.Matrix_Element{
Key: elm.Key,
Value: elm.Val,
})
Expand Down Expand Up @@ -583,16 +583,16 @@ func (m *Matrix) FromProto(in *pb.Matrix) {
return
}

if len(in.Vectors) < 1 {
if len(in.GetVectors()) < 1 {
return
}

if m.Vectors == nil {
m.Vectors = []*Vector{}
}

for i := range in.Vectors {
m.Vectors = append(m.Vectors, NewVectorFromProto(in.Vectors[i]))
for i := range in.GetVectors() {
m.Vectors = append(m.Vectors, NewVectorFromProto(in.GetVectors()[i]))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/flightplan/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ scenario "basic" {
}`, modulePath, test.expr)
fp, err := testDecodeHCL(t, []byte(hcl), DecodeTargetAll)
require.NoError(t, err)
require.Equal(t, 1, len(fp.Modules))
require.Len(t, fp.Modules, 1)
v, ok := fp.Modules[0].Attrs["something"]
require.True(t, ok)
require.Equal(t, test.expected, v.AsString())
Expand Down
4 changes: 2 additions & 2 deletions internal/flightplan/sample_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func sampleElementsFor(

if subsetFrame.ScenarioFilter != nil {
scenario := NewScenario()
scenario.Name = subsetFrame.ScenarioFilter.Name
scenario.Name = subsetFrame.ScenarioFilter.GetName()
elm.Scenario = scenario.Ref()
}
}
Expand All @@ -395,7 +395,7 @@ func sampleElementsFor(

if subsetFrame.ScenarioFilter != nil {
scenario := NewScenario()
scenario.Name = subsetFrame.ScenarioFilter.Name
scenario.Name = subsetFrame.ScenarioFilter.GetName()
scenario.Variants = vectors[i]
elm.Scenario = scenario.Ref()
}
Expand Down
16 changes: 8 additions & 8 deletions internal/flightplan/sample_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ sample "all" {
fp, err := testDecodeHCL(t, ws.GetFlightplan().GetEnosHcl()["enos-test.hcl"], DecodeTargetAll)
require.NoError(t, err)
require.NotNil(t, fp)
require.Equal(t, 1, len(fp.Samples))
require.Len(t, fp.Samples, 1)
samp := fp.Samples[0]

frame, decRes := samp.Frame(context.Background(), ws, test.filter)
require.Equal(t, 0, len(decRes.GetDiagnostics()))
require.Empty(t, decRes.GetDiagnostics())

subFrame, ok := frame.SubsetFrames[subsetName]
require.True(t, ok)
Expand All @@ -412,11 +412,11 @@ sample "all" {

for i := range test.expected {
test.expected[i].Sample = samp.Ref()
require.EqualValues(t, test.expected[i].Sample, elements[i].Sample)
require.EqualValues(t, test.expected[i].Subset, elements[i].Subset)
require.EqualValues(t, test.expected[i].Scenario, elements[i].Scenario)
gotAttrs := elements[i].Attributes.AsMap()
for name, val := range test.expected[i].Attributes.AsMap() {
require.EqualValues(t, test.expected[i].GetSample(), elements[i].GetSample())
require.EqualValues(t, test.expected[i].GetSubset(), elements[i].GetSubset())
require.EqualValues(t, test.expected[i].GetScenario(), elements[i].GetScenario())
gotAttrs := elements[i].GetAttributes().AsMap()
for name, val := range test.expected[i].GetAttributes().AsMap() {
attr, ok := gotAttrs[name]
require.True(t, ok, "did not find expected attribute %s", name)
require.EqualValues(t, val, attr)
Expand Down Expand Up @@ -537,7 +537,7 @@ func Test_SampleFrame_FilterPercentage(t *testing.T) {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, test.expected, pct)
require.InEpsilon(t, test.expected, pct, 0)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/flightplan/sample_subset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ sample "foo" {
if test.expected == nil {
for i := range samp.Subsets {
frame, decRes := samp.Subsets[i].Frame(context.Background(), test.ws)
require.Equal(t, 0, len(decRes.GetDiagnostics()))
require.Empty(t, decRes.GetDiagnostics())
testRequireEqualSampleSubsetFrame(t, nil, frame)
}

Expand All @@ -268,7 +268,7 @@ sample "foo" {
for _, d := range decRes.GetDiagnostics() {
msg += fmt.Sprintf(" %s", diagnostics.String(d))
}
require.Equal(t, 0, len(decRes.GetDiagnostics()), msg)
require.Emptyf(t, decRes.GetDiagnostics(), msg)

testRequireEqualSampleSubsetFrame(t, test.expected[i], frame)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/flightplan/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,15 @@ sample "foodle" {
fp, err := testDecodeHCL(t, test.ws.GetFlightplan().GetEnosHcl()["enos-test.hcl"], DecodeTargetAll)
require.NoError(t, err)
require.NotNil(t, fp)
require.Equal(t, 1, len(fp.Samples))
require.Len(t, fp.Samples, 1)
samp := fp.Samples[0]
frame, decRes := samp.Frame(context.Background(), test.ws, test.filter)
require.EqualValues(t, samp, frame.Sample)

// Handle cases where we don't expect to get a valid frame
if test.expected == nil {
require.Equal(t, int32(0), frame.Size())
require.Equal(t, 0, len(decRes.GetDiagnostics()))
require.Empty(t, decRes.GetDiagnostics())

return
}
Expand Down
Loading