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

fix: remove json indirection, restructure package #2

Merged
merged 3 commits into from
Dec 7, 2021
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: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ All the formats above are transformed into JSON so that they can be used as inpu

## Development

All code is contained within the `pkg` directory and each file has a corresponding test. Test fixtures are included in the `test/fixtures` directory.

Tests can be run using the `go test` command:

```bash
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions pkg/json.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/json_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/terraform_plan.go → terraform_plan.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parsers

import (
"encoding/json"
"fmt"
"math/rand"
"reflect"
Expand Down Expand Up @@ -129,7 +130,7 @@ func isValidResourceActions(resourceAction ResourceActions, isFullScan bool) boo

func ParseTerraformPlan(p []byte, v *interface{}) error {
var tfPlanJson TerraformPlanJson
if err := ParseJSON(p, &tfPlanJson); err != nil {
if err := json.Unmarshal(p, &tfPlanJson); err != nil {
return errors.Wrap(err, "failed to parse terraform-plan json payload")
}
// Currently being used only by Terraform Cloud integration
Expand Down
7 changes: 4 additions & 3 deletions pkg/terraform_plan_test.go → terraform_plan_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parsers

import (
"encoding/json"
"fmt"
"io/ioutil"
"path"
Expand All @@ -20,7 +21,7 @@ func getExpectedResult(planFileName, expectedResultsFolder string) (TerraformSca
return nil, err
}
var expectedResult TerraformScanInput
err = ParseJSON(expectedResultJsonFile, &expectedResult)
err = json.Unmarshal(expectedResultJsonFile, &expectedResult)
if err != nil {
return nil, err
}
Expand All @@ -43,7 +44,7 @@ func testPlanFile(t *testing.T, fileName, root string, wg *sync.WaitGroup) {
t.Errorf("%v, failed with file %s", err, fileName)
}
var planJson TerraformPlanJson
err = ParseJSON(file, &planJson)
err = json.Unmarshal(file, &planJson)
if err != nil {
t.Errorf("%v, failed with file %s", err, fileName)
}
Expand All @@ -64,7 +65,7 @@ func testPlanFile(t *testing.T, fileName, root string, wg *sync.WaitGroup) {
}

func TestTerraformPlanParser(t *testing.T) {
root := "../test/fixtures/terraform-plans/"
root := "./testdata/terraform-plans/"
files, err := ioutil.ReadDir(root)
if err != nil {
t.Error(err)
Expand Down
Binary file removed test/.DS_Store
Binary file not shown.
Binary file removed test/fixtures/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.