From 0c9cdc0a9476b23089cde32a76139f90a1d18547 Mon Sep 17 00:00:00 2001 From: Samuel Manzer Date: Sun, 29 Oct 2023 20:54:11 -0700 Subject: [PATCH] Add Buck Build + Test Capabilities (#404) Summary: Add these capabilities * Build the ttpforge binary using internal golang dependencies and tooling * Run unit tests using buck Reviewed By: l50 Differential Revision: D50708311 --- cmd/listttps_test.go | 5 +- cmd/run_test.go | 6 +- pkg/args/spec_test.go | 25 +++-- pkg/blocks/basicstep_test.go | 12 +-- pkg/blocks/common_test.go | 9 +- pkg/blocks/context_test.go | 21 ++-- pkg/blocks/createfile_test.go | 17 ++-- pkg/blocks/editstep_test.go | 43 ++++----- pkg/blocks/fetchuri_test.go | 18 ++-- pkg/blocks/filestep_test.go | 27 +++--- pkg/blocks/printstr_test.go | 17 ++-- pkg/blocks/removepath_test.go | 15 ++- pkg/blocks/step_test.go | 11 +-- pkg/blocks/subttp_test.go | 9 +- pkg/blocks/ttps_test.go | 31 +++--- pkg/logging/logger_test.go | 17 ++-- pkg/network/README.md | 153 ------------------------------ pkg/network/proxy.go | 81 ---------------- pkg/network/proxy_test.go | 126 ------------------------ pkg/outputs/outputs_test.go | 17 ++-- pkg/preprocess/preprocess_test.go | 5 +- pkg/repos/repo_test.go | 29 +++--- pkg/repos/repocollection_test.go | 31 +++--- 23 files changed, 172 insertions(+), 553 deletions(-) delete mode 100644 pkg/network/README.md delete mode 100644 pkg/network/proxy.go delete mode 100644 pkg/network/proxy_test.go diff --git a/cmd/listttps_test.go b/cmd/listttps_test.go index 73f4acdf..19164e6e 100644 --- a/cmd/listttps_test.go +++ b/cmd/listttps_test.go @@ -17,13 +17,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package cmd_test +package cmd import ( "path/filepath" "testing" - "github.com/facebookincubator/ttpforge/cmd" "github.com/stretchr/testify/require" ) @@ -41,7 +40,7 @@ func TestListTTPs(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - rc := cmd.BuildRootCommand(nil) + rc := BuildRootCommand(nil) rc.SetArgs([]string{"list", "ttps", "-c", testConfigFilePath}) err := rc.Execute() if tc.wantError { diff --git a/cmd/run_test.go b/cmd/run_test.go index 80ca4145..3b7ebd1f 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -17,14 +17,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package cmd_test +package cmd import ( "bytes" "path/filepath" + "testing" - "github.com/facebookincubator/ttpforge/cmd" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -128,7 +128,7 @@ func TestRun(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { var stdoutBuf, stderrBuf bytes.Buffer - rc := cmd.BuildRootCommand(&cmd.Config{ + rc := BuildRootCommand(&Config{ Stdout: &stdoutBuf, Stderr: &stderrBuf, }) diff --git a/pkg/args/spec_test.go b/pkg/args/spec_test.go index 7b750a3c..a10be24f 100644 --- a/pkg/args/spec_test.go +++ b/pkg/args/spec_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package args_test +package args import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/args" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -31,14 +30,14 @@ func TestValidateArgs(t *testing.T) { testCases := []struct { name string - specs []args.Spec + specs []Spec argKvStrs []string expectedResult map[string]any wantError bool }{ { name: "Parse String and Integer Arguments", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -59,7 +58,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Parse String and Integer Argument (Default Value)", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -80,7 +79,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Handle Extra Equals", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -100,7 +99,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Invalid Inputs (no '=')", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -116,7 +115,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Invalid Inputs (Missing Required Argument)", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -131,7 +130,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Argument Name Not In Specs", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -147,7 +146,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Duplicate Name in Specs", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -162,7 +161,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Wrong Type (string instead of int)", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", }, @@ -179,7 +178,7 @@ func TestValidateArgs(t *testing.T) { }, { name: "Default Value Wrong Type (string instead of int)", - specs: []args.Spec{ + specs: []Spec{ { Name: "alpha", Type: "int", @@ -195,7 +194,7 @@ func TestValidateArgs(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - args, err := args.ParseAndValidate(tc.specs, tc.argKvStrs) + args, err := ParseAndValidate(tc.specs, tc.argKvStrs) if tc.wantError { require.Error(t, err) return diff --git a/pkg/blocks/basicstep_test.go b/pkg/blocks/basicstep_test.go index f67ed137..f8ee0e76 100755 --- a/pkg/blocks/basicstep_test.go +++ b/pkg/blocks/basicstep_test.go @@ -17,13 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" @@ -65,7 +63,7 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttps blocks.TTP + var ttps TTP err := yaml.Unmarshal([]byte(tc.content), &ttps) if tc.wantError { assert.Error(t, err) @@ -85,9 +83,9 @@ outputs: first: filters: - json_path: foo.bar` - var s blocks.BasicStep - execCtx := blocks.TTPExecutionContext{ - Cfg: blocks.TTPExecutionConfig{ + var s BasicStep + execCtx := TTPExecutionContext{ + Cfg: TTPExecutionConfig{ Args: map[string]any{ "myarg": "baz", }, diff --git a/pkg/blocks/common_test.go b/pkg/blocks/common_test.go index 33f5f720..58ea7bd6 100755 --- a/pkg/blocks/common_test.go +++ b/pkg/blocks/common_test.go @@ -17,7 +17,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "io/fs" @@ -27,7 +27,6 @@ import ( "strings" "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/stretchr/testify/assert" ) @@ -78,7 +77,7 @@ func TestFetchAbs(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - result, err := blocks.FetchAbs(tc.inputPath, tc.inputWorkdir) + result, err := FetchAbs(tc.inputPath, tc.inputWorkdir) if tc.expectError { assert.Error(t, err) @@ -161,7 +160,7 @@ func TestFindFilePath(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - result, err := blocks.FindFilePath(tc.inputPath, tc.inputWorkdir, tc.fsStat) + result, err := FindFilePath(tc.inputPath, tc.inputWorkdir, tc.fsStat) if tc.expectError { assert.Error(t, err) @@ -213,7 +212,7 @@ func TestFetchEnv(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := blocks.FetchEnv(tt.environ) + result := FetchEnv(tt.environ) sort.Strings(result) sort.Strings(tt.expected) diff --git a/pkg/blocks/context_test.go b/pkg/blocks/context_test.go index 147b00ba..bdedeba8 100644 --- a/pkg/blocks/context_test.go +++ b/pkg/blocks/context_test.go @@ -17,31 +17,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestExpandVariablesStepResults(t *testing.T) { // build the test fixture used across all cases - stepResults := blocks.NewStepResultsRecord() - stepResults.ByName["first_step"] = &blocks.ExecutionResult{ - ActResult: blocks.ActResult{ + stepResults := NewStepResultsRecord() + stepResults.ByName["first_step"] = &ExecutionResult{ + ActResult: ActResult{ Stdout: "hello", }, } - stepResults.ByName["second_step"] = &blocks.ExecutionResult{ - ActResult: blocks.ActResult{ + stepResults.ByName["second_step"] = &ExecutionResult{ + ActResult: ActResult{ Stdout: "world", }, } - stepResults.ByName["third_step"] = &blocks.ExecutionResult{ - ActResult: blocks.ActResult{ + stepResults.ByName["third_step"] = &ExecutionResult{ + ActResult: ActResult{ Stdout: `{"foo":{"bar":"baz"}}`, Outputs: map[string]string{ "myresult": "baz", @@ -51,8 +50,8 @@ func TestExpandVariablesStepResults(t *testing.T) { stepResults.ByIndex = append(stepResults.ByIndex, stepResults.ByName["first_step"]) stepResults.ByIndex = append(stepResults.ByIndex, stepResults.ByName["second_step"]) stepResults.ByIndex = append(stepResults.ByIndex, stepResults.ByName["third_step"]) - execCtx := blocks.TTPExecutionContext{ - Cfg: blocks.TTPExecutionConfig{ + execCtx := TTPExecutionContext{ + Cfg: TTPExecutionConfig{ Args: map[string]any{ "arg1": "myarg1", "arg2": "myarg2", diff --git a/pkg/blocks/createfile_test.go b/pkg/blocks/createfile_test.go index 2ae7b165..367b6062 100755 --- a/pkg/blocks/createfile_test.go +++ b/pkg/blocks/createfile_test.go @@ -17,13 +17,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "os" "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/facebookincubator/ttpforge/pkg/testutils" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -34,14 +33,14 @@ func TestCreateFileExecute(t *testing.T) { testCases := []struct { name string description string - step *blocks.CreateFileStep + step *CreateFileStep fsysContents map[string][]byte expectExecuteError bool }{ { name: "Create Valid File", description: "Create a single unremarkable file", - step: &blocks.CreateFileStep{ + step: &CreateFileStep{ Path: "valid-file.txt", Contents: "hello world", }, @@ -49,7 +48,7 @@ func TestCreateFileExecute(t *testing.T) { { name: "Nested Directories", description: "Afero should handle this under the hood", - step: &blocks.CreateFileStep{ + step: &CreateFileStep{ Path: "/directory/does/not/exist", Contents: "should still work", }, @@ -57,7 +56,7 @@ func TestCreateFileExecute(t *testing.T) { { name: "Already Exists (No Overwrite)", description: "Should fail because file already exists", - step: &blocks.CreateFileStep{ + step: &CreateFileStep{ Path: "already-exists.txt", Contents: "will fail", }, @@ -69,7 +68,7 @@ func TestCreateFileExecute(t *testing.T) { { name: "Already Exists (With Overwrite)", description: "Should succeed and overwrite existing file", - step: &blocks.CreateFileStep{ + step: &CreateFileStep{ Path: "already-exists.txt", Contents: "will succeed", Overwrite: true, @@ -81,7 +80,7 @@ func TestCreateFileExecute(t *testing.T) { { name: "Set Permissions Manually", description: "Make the file read-only", - step: &blocks.CreateFileStep{ + step: &CreateFileStep{ Path: "make-read-only", Contents: "very-read-only", Mode: 0400, @@ -101,7 +100,7 @@ func TestCreateFileExecute(t *testing.T) { } // execute and check error - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext _, err := tc.step.Execute(execCtx) if tc.expectExecuteError { require.Error(t, err) diff --git a/pkg/blocks/editstep_test.go b/pkg/blocks/editstep_test.go index eec0baea..df889422 100755 --- a/pkg/blocks/editstep_test.go +++ b/pkg/blocks/editstep_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -41,11 +40,11 @@ steps: - old: another new: one` - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(content), &ttp) require.NoError(t, err) - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) require.NoError(t, err) } @@ -62,11 +61,11 @@ steps: - old: another new: one` - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(content), &ttp) require.NoError(t, err) - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) require.Error(t, err) assert.Equal(t, "edit #2 is missing 'new:'", err.Error()) @@ -85,11 +84,11 @@ steps: - old: another new: one` - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(content), &ttp) require.NoError(t, err) - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) require.Error(t, err) assert.Equal(t, "edit #1 is missing 'old:'", err.Error()) @@ -103,7 +102,7 @@ steps: edit_file: yolo edits: haha` - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(content), &ttp) require.Error(t, err) } @@ -115,11 +114,11 @@ steps: - name: no_edits edit_file: yolo` - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(content), &ttp) require.NoError(t, err) - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) assert.Equal(t, "no edits specified", err.Error()) } @@ -133,7 +132,7 @@ edits: - old: another new: one` - var step blocks.EditStep + var step EditStep err := yaml.Unmarshal([]byte(content), &step) require.NoError(t, err) @@ -142,7 +141,7 @@ edits: require.NoError(t, err) step.FileSystem = testFs - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext err = step.Validate(execCtx) require.NoError(t, err) @@ -166,7 +165,7 @@ edits: - old: another new: one` - var step blocks.EditStep + var step EditStep err := yaml.Unmarshal([]byte(content), &step) require.NoError(t, err) @@ -176,7 +175,7 @@ edits: require.NoError(t, err) step.FileSystem = testFs - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext err = step.Validate(execCtx) require.NoError(t, err) @@ -208,7 +207,7 @@ moarawesomestuff` # function call removed by TTP moarawesomestuff` - var step blocks.EditStep + var step EditStep err := yaml.Unmarshal([]byte(content), &step) require.NoError(t, err) @@ -216,7 +215,7 @@ moarawesomestuff` err = afero.WriteFile(testFs, "b.txt", []byte(fileContentsToEdit), 0644) require.NoError(t, err) step.FileSystem = testFs - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext err = step.Validate(execCtx) require.NoError(t, err) @@ -251,7 +250,7 @@ moarawesomestuff` )*/ moarawesomestuff` - var step blocks.EditStep + var step EditStep err := yaml.Unmarshal([]byte(content), &step) require.NoError(t, err) @@ -260,7 +259,7 @@ moarawesomestuff` require.NoError(t, err) step.FileSystem = testFs - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext err = step.Validate(execCtx) require.NoError(t, err) @@ -282,7 +281,7 @@ edits: fileContentsToEdit := `hello` - var step blocks.EditStep + var step EditStep err := yaml.Unmarshal([]byte(content), &step) require.NoError(t, err) @@ -291,11 +290,11 @@ edits: require.NoError(t, err) step.FileSystem = testFs - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext err = step.Validate(execCtx) require.NoError(t, err) - _, err = step.Execute(blocks.TTPExecutionContext{}) + _, err = step.Execute(TTPExecutionContext{}) require.Error(t, err, "not finding a search string should result in an error") assert.Equal(t, "pattern 'not_going_to_find_this' from edit #1 was not found in file b.txt", err.Error()) } diff --git a/pkg/blocks/fetchuri_test.go b/pkg/blocks/fetchuri_test.go index d59a2024..b05b96ca 100755 --- a/pkg/blocks/fetchuri_test.go +++ b/pkg/blocks/fetchuri_test.go @@ -17,7 +17,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "fmt" @@ -26,8 +26,6 @@ import ( "os" "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" @@ -81,7 +79,7 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttps blocks.TTP + var ttps TTP err := yaml.Unmarshal([]byte(tc.content), &ttps) if tc.wantError { assert.Error(t, err) @@ -179,12 +177,12 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttps blocks.TTP + var ttps TTP err := yaml.Unmarshal([]byte(tc.content), &ttps) assert.NoError(t, err) - execCtx := blocks.TTPExecutionContext{ - Cfg: blocks.TTPExecutionConfig{ + execCtx := TTPExecutionContext{ + Cfg: TTPExecutionConfig{ Args: map[string]any{}, }, } @@ -208,9 +206,9 @@ fetch_uri: OVERWRITTEN location: /tmp/test.html overwrite: true ` - var s blocks.FetchURIStep - execCtx := blocks.TTPExecutionContext{ - Cfg: blocks.TTPExecutionConfig{ + var s FetchURIStep + execCtx := TTPExecutionContext{ + Cfg: TTPExecutionConfig{ Args: map[string]any{}, }, } diff --git a/pkg/blocks/filestep_test.go b/pkg/blocks/filestep_test.go index be1a927e..d6abb3fd 100755 --- a/pkg/blocks/filestep_test.go +++ b/pkg/blocks/filestep_test.go @@ -17,13 +17,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "runtime" "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" @@ -49,7 +48,7 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttps blocks.TTP + var ttps TTP err := yaml.Unmarshal([]byte(tc.content), &ttps) if tc.wantError { assert.Error(t, err) @@ -65,20 +64,20 @@ func TestInferExecutor(t *testing.T) { filePath string expectedExec string }{ - {filePath: "script.sh", expectedExec: blocks.ExecutorSh}, - {filePath: "script.py", expectedExec: blocks.ExecutorPython}, - {filePath: "script.rb", expectedExec: blocks.ExecutorRuby}, - {filePath: "script.pwsh", expectedExec: blocks.ExecutorPowershell}, - {filePath: "script.ps1", expectedExec: blocks.ExecutorPowershell}, - {filePath: "script.bat", expectedExec: blocks.ExecutorCmd}, - {filePath: "binary", expectedExec: blocks.ExecutorBinary}, + {filePath: "script.sh", expectedExec: ExecutorSh}, + {filePath: "script.py", expectedExec: ExecutorPython}, + {filePath: "script.rb", expectedExec: ExecutorRuby}, + {filePath: "script.pwsh", expectedExec: ExecutorPowershell}, + {filePath: "script.ps1", expectedExec: ExecutorPowershell}, + {filePath: "script.bat", expectedExec: ExecutorCmd}, + {filePath: "binary", expectedExec: ExecutorBinary}, {filePath: "unknown.xyz", expectedExec: getDefaultExecutor()}, - {filePath: "", expectedExec: blocks.ExecutorBinary}, + {filePath: "", expectedExec: ExecutorBinary}, } for _, testCase := range testCases { t.Run(testCase.filePath, func(t *testing.T) { - executor := blocks.InferExecutor(testCase.filePath) + executor := InferExecutor(testCase.filePath) assert.Equal(t, testCase.expectedExec, executor, "Expected executor %q for file path %q, but got %q", testCase.expectedExec, testCase.filePath, executor) }) } @@ -86,7 +85,7 @@ func TestInferExecutor(t *testing.T) { func getDefaultExecutor() string { if runtime.GOOS == "windows" { - return blocks.ExecutorCmd + return ExecutorCmd } - return blocks.ExecutorSh + return ExecutorSh } diff --git a/pkg/blocks/printstr_test.go b/pkg/blocks/printstr_test.go index e9dc6ac9..781193a3 100755 --- a/pkg/blocks/printstr_test.go +++ b/pkg/blocks/printstr_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -31,14 +30,14 @@ func TestPrintStrExecute(t *testing.T) { testCases := []struct { name string description string - action *blocks.PrintStrAction + action *PrintStrAction expectExecuteError bool expectedStdout string }{ { name: "Simple Print", description: "Just Print a String", - action: &blocks.PrintStrAction{ + action: &PrintStrAction{ Message: "hello", }, expectedStdout: "hello\n", @@ -46,7 +45,7 @@ func TestPrintStrExecute(t *testing.T) { { name: "Print Step Output", description: "Should be Expanded", - action: &blocks.PrintStrAction{ + action: &PrintStrAction{ Message: "value is $forge.steps.first_step.stdout", }, expectedStdout: "value is first-step-output\n", @@ -56,11 +55,11 @@ func TestPrintStrExecute(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // for use testing output variables - execCtx := blocks.TTPExecutionContext{ - StepResults: &blocks.StepResultsRecord{ - ByName: map[string]*blocks.ExecutionResult{ + execCtx := TTPExecutionContext{ + StepResults: &StepResultsRecord{ + ByName: map[string]*ExecutionResult{ "first_step": { - ActResult: blocks.ActResult{ + ActResult: ActResult{ Stdout: "first-step-output", }, }, diff --git a/pkg/blocks/removepath_test.go b/pkg/blocks/removepath_test.go index d0e4b773..c7ba1459 100755 --- a/pkg/blocks/removepath_test.go +++ b/pkg/blocks/removepath_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/facebookincubator/ttpforge/pkg/testutils" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -33,14 +32,14 @@ func TestRemovePathExecute(t *testing.T) { testCases := []struct { name string description string - step *blocks.RemovePathAction + step *RemovePathAction fsysContents map[string][]byte expectExecuteError bool }{ { name: "Remove Valid File", description: "Remove a single unremarkable file", - step: &blocks.RemovePathAction{ + step: &RemovePathAction{ Path: "valid-file.txt", }, fsysContents: map[string][]byte{ @@ -50,7 +49,7 @@ func TestRemovePathExecute(t *testing.T) { { name: "Remove Non-Existent File", description: "Remove a non-existent file - should error", - step: &blocks.RemovePathAction{ + step: &RemovePathAction{ Path: "does-not-exist.txt", }, fsysContents: map[string][]byte{ @@ -61,7 +60,7 @@ func TestRemovePathExecute(t *testing.T) { { name: "Remove Directory - Success", description: "Set Recursive to make directory removal succeed", - step: &blocks.RemovePathAction{ + step: &RemovePathAction{ Path: "valid-directory", Recursive: true, }, @@ -72,7 +71,7 @@ func TestRemovePathExecute(t *testing.T) { { name: "Remove Directory - Failure", description: "Refuse to remove directory because `recursive: true` was not specified", - step: &blocks.RemovePathAction{ + step: &RemovePathAction{ Path: "valid-directory", }, fsysContents: map[string][]byte{ @@ -94,7 +93,7 @@ func TestRemovePathExecute(t *testing.T) { } // execute and check error - var execCtx blocks.TTPExecutionContext + var execCtx TTPExecutionContext _, err := tc.step.Execute(execCtx) if tc.expectExecuteError { require.Error(t, err) diff --git a/pkg/blocks/step_test.go b/pkg/blocks/step_test.go index ead0237d..d0dba37f 100644 --- a/pkg/blocks/step_test.go +++ b/pkg/blocks/step_test.go @@ -17,14 +17,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "fmt" "os" "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -75,8 +74,8 @@ inline: this will error`, for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var s blocks.Step - var execCtx blocks.TTPExecutionContext + var s Step + var execCtx TTPExecutionContext // parse the step err := yaml.Unmarshal([]byte(tc.content), &s) @@ -154,8 +153,8 @@ cleanup: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var s blocks.Step - var execCtx blocks.TTPExecutionContext + var s Step + var execCtx TTPExecutionContext // hack to get a valid temporary path without creating it tmpFile, err := os.CreateTemp("", "ttpforge-test-cleanup-default") diff --git a/pkg/blocks/subttp_test.go b/pkg/blocks/subttp_test.go index d7c54c48..2ac633ce 100755 --- a/pkg/blocks/subttp_test.go +++ b/pkg/blocks/subttp_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/facebookincubator/ttpforge/pkg/repos" "github.com/facebookincubator/ttpforge/pkg/testutils" "github.com/spf13/afero" @@ -119,15 +118,15 @@ ttp: with/cleanup.yaml`, for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - var step blocks.SubTTPStep + var step SubTTPStep err := yaml.Unmarshal([]byte(tc.stepYAML), &step) require.NoError(t, err, "step YAML should unmarshal safely") repo, err := tc.spec.Load(tc.fsys, "") require.NoError(t, err) - execCtx := blocks.TTPExecutionContext{ - Cfg: blocks.TTPExecutionConfig{ + execCtx := TTPExecutionContext{ + Cfg: TTPExecutionConfig{ Repo: repo, }, } diff --git a/pkg/blocks/ttps_test.go b/pkg/blocks/ttps_test.go index 7d7be743..4890970f 100755 --- a/pkg/blocks/ttps_test.go +++ b/pkg/blocks/ttps_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package blocks_test +package blocks import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/blocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -60,7 +59,7 @@ steps: } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttps blocks.TTP + var ttps TTP err := yaml.Unmarshal([]byte(tc.content), &ttps) assert.Error(t, err, "steps with ambiguous types should yield an error when parsed") }) @@ -121,7 +120,7 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(tc.content), &ttp) if tc.wantError { assert.Error(t, err) @@ -157,7 +156,7 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(tc.content), &ttp) if tc.wantError { assert.Error(t, err) @@ -165,7 +164,7 @@ steps: assert.NoError(t, err) } - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) if tc.wantError { assert.Error(t, err) } else { @@ -179,7 +178,7 @@ func TestTTP(t *testing.T) { testCases := []struct { name string content string - execConfig blocks.TTPExecutionConfig + execConfig TTPExecutionConfig expectedByIndexOut map[int]string expectedByNameOut map[string]string wantError bool @@ -205,7 +204,7 @@ steps: inline: echo "step4" cleanup: inline: echo "cleanup4"`, - execConfig: blocks.TTPExecutionConfig{}, + execConfig: TTPExecutionConfig{}, expectedByIndexOut: map[int]string{ 0: "step1\n", 1: "step2\n", @@ -237,7 +236,7 @@ steps: - name: optional_step_2 inline: echo "optional step 2" {{ end }}`, - execConfig: blocks.TTPExecutionConfig{ + execConfig: TTPExecutionConfig{ Args: map[string]interface{}{ "arg1": "victory", "do_optional_step_2": true, @@ -270,7 +269,7 @@ steps: inline: echo "first output is baz" - name: step3 inline: echo "arg value is {{ .Args.arg1 }}"`, - execConfig: blocks.TTPExecutionConfig{ + execConfig: TTPExecutionConfig{ Args: map[string]interface{}{ "arg1": "victory", }, @@ -297,7 +296,7 @@ steps: A B EOF`, - execConfig: blocks.TTPExecutionConfig{}, + execConfig: TTPExecutionConfig{}, expectedByIndexOut: map[int]string{ 0: "A\nB\n", }, @@ -311,18 +310,18 @@ steps: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Render the templated TTP first - ttp, err := blocks.RenderTemplatedTTP(tc.content, &tc.execConfig) + ttp, err := RenderTemplatedTTP(tc.content, &tc.execConfig) if err != nil { t.Fatalf("failed to render and unmarshal templated TTP: %v", err) return } // validate the TTP - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) require.NoError(t, err) // run it - stepResults, err := ttp.Execute(&blocks.TTPExecutionContext{ + stepResults, err := ttp.Execute(&TTPExecutionContext{ Cfg: tc.execConfig, }) if tc.wantError { @@ -378,10 +377,10 @@ mitre: for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var ttp blocks.TTP + var ttp TTP err := yaml.Unmarshal([]byte(tc.content), &ttp) require.NoError(t, err) - err = ttp.Validate(blocks.TTPExecutionContext{}) + err = ttp.Validate(TTPExecutionContext{}) if tc.wantError { assert.Error(t, err) } else { diff --git a/pkg/logging/logger_test.go b/pkg/logging/logger_test.go index abe2bcad..27d05148 100755 --- a/pkg/logging/logger_test.go +++ b/pkg/logging/logger_test.go @@ -17,13 +17,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package logging_test +package logging import ( "os" "testing" - "github.com/facebookincubator/ttpforge/pkg/logging" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" @@ -39,12 +38,12 @@ import ( func TestInitLogStacktraceNoLogfile(t *testing.T) { core, recordedLogs := observer.New(zapcore.InfoLevel) - err := logging.InitLog(logging.Config{ + err := InitLog(Config{ Stacktrace: true, }) require.NoError(t, err) - logger := logging.L().WithOptions(zap.WrapCore(func(c zapcore.Core) zapcore.Core { return core })) + logger := L().WithOptions(zap.WrapCore(func(c zapcore.Core) zapcore.Core { return core })) logger.Error("should produce a stack trace") @@ -61,13 +60,13 @@ func TestInitLog(t *testing.T) { tests := []struct { name string - config logging.Config + config Config logFunc func(t *testing.T, testLogger *zap.SugaredLogger) checkFunc func(t *testing.T, logFileContents string) }{ { name: "verbose", - config: logging.Config{ + config: Config{ Verbose: true, }, logFunc: func(t *testing.T, testLogger *zap.SugaredLogger) { @@ -79,7 +78,7 @@ func TestInitLog(t *testing.T) { }, { name: "no-color", - config: logging.Config{ + config: Config{ NoColor: true, }, logFunc: func(t *testing.T, testLogger *zap.SugaredLogger) { @@ -103,11 +102,11 @@ func TestInitLog(t *testing.T) { cfg.LogFile = logFile // initialize the logger for this test case - err = logging.InitLog(cfg) + err = InitLog(cfg) require.NoError(t, err) // actually create logs - tc.logFunc(t, logging.L()) + tc.logFunc(t, L()) // read back result content, err := os.ReadFile(logFile) diff --git a/pkg/network/README.md b/pkg/network/README.md deleted file mode 100644 index bfab53f0..00000000 --- a/pkg/network/README.md +++ /dev/null @@ -1,153 +0,0 @@ -# TTPForge/network - -The `network` package is a part of the TTPForge. - ---- - -## Table of contents - -- [Functions](#functions) -- [Installation](#installation) -- [Usage](#usage) -- [Tests](#tests) -- [Contributing](#contributing) -- [License](#license) - ---- - -## Functions - -### DisableHTTPProxy() - -```go -DisableHTTPProxy() -``` - -DisableHTTPProxy unsets the "http_proxy" environment variable. -This disables the HTTP proxy for network operations in the current process. - ---- - -### DisableHTTPSProxy() - -```go -DisableHTTPSProxy() -``` - -DisableHTTPSProxy unsets the "https_proxy" and "http_proxy" -environment variables. This disables the HTTPS proxy for network -operations in the current process. - -**Parameters:** - -proxy: A string representing the URL of the proxy server to be used for HTTPS connections. - ---- - -### DisableNoProxy() - -```go -DisableNoProxy() -``` - -DisableNoProxy unsets the "no_proxy" environment variable. -This clears the list of domains excluded from being -proxied for network operations in the current process. - ---- - -### EnableHTTPProxy(string) - -```go -EnableHTTPProxy(string) -``` - -EnableHTTPProxy sets the "http_proxy" environment variable -to the provided proxy string. This enables an HTTP proxy -for network operations in the current process. - -**Parameters:** - -proxy: A string representing the URL of the proxy server to be used for HTTP connections. - ---- - -### EnableHTTPSProxy(string) - -```go -EnableHTTPSProxy(string) -``` - -EnableHTTPSProxy sets the environment variables "https_proxy" -and "http_proxy" to the provided proxy string. -This enables an HTTPS proxy for network operations in the current process. - -**Parameters:** - -proxy: A string representing the URL of the proxy server to be used for HTTPS connections. - ---- - -### EnableNoProxy(string) - -```go -EnableNoProxy(string) -``` - -EnableNoProxy sets the "no_proxy" environment variable to -the provided domains string. This excludes the specified domains -from being proxied for network operations in the current process. - -**Parameters:** - -domains: A string representing a comma-separated list of domain names -to be excluded from proxying. - ---- - -## Installation - -To use the TTPForge/network package, you first need to install it. -Follow the steps below to install via go get. - -```bash -go get github.com/facebookincubator/ttpforge/network -``` - ---- - -## Usage - -After installation, you can import the package in your Go project -using the following import statement: - -```go -import "github.com/facebookincubator/ttpforge/network" -``` - ---- - -## Tests - -To ensure the package is working correctly, run the following -command to execute the tests for `TTPForge/network`: - -```bash -go test -v -``` - ---- - -## Contributing - -Pull requests are welcome. For major changes, -please open an issue first to discuss what -you would like to change. - ---- - -## License - -This project is licensed under the MIT -License - see the [LICENSE](https://github.com/facebookincubator/TTPForge/blob/main/LICENSE) -file for details. diff --git a/pkg/network/proxy.go b/pkg/network/proxy.go deleted file mode 100644 index 646684d4..00000000 --- a/pkg/network/proxy.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright © 2023-present, Meta Platforms, Inc. and affiliates -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -package network - -import "os" - -// EnableHTTPSProxy sets the environment variables "https_proxy" -// and "http_proxy" to the provided proxy string. -// This enables an HTTPS proxy for network operations in the current process. -// -// **Parameters:** -// -// proxy: A string representing the URL of the proxy server to be used for HTTPS connections. -func EnableHTTPSProxy(proxy string) { - os.Setenv("https_proxy", proxy) - os.Setenv("http_proxy", proxy) -} - -// DisableHTTPSProxy unsets the "https_proxy" and "http_proxy" -// environment variables. This disables the HTTPS proxy for network -// operations in the current process. -// -// **Parameters:** -// -// proxy: A string representing the URL of the proxy server to be used for HTTPS connections. -func DisableHTTPSProxy() { - os.Unsetenv("https_proxy") -} - -// EnableNoProxy sets the "no_proxy" environment variable to -// the provided domains string. This excludes the specified domains -// from being proxied for network operations in the current process. -// -// **Parameters:** -// -// domains: A string representing a comma-separated list of domain names -// to be excluded from proxying. -func EnableNoProxy(domains string) { - os.Setenv("no_proxy", domains) -} - -// DisableNoProxy unsets the "no_proxy" environment variable. -// This clears the list of domains excluded from being -// proxied for network operations in the current process. -func DisableNoProxy() { - os.Unsetenv("no_proxy") -} - -// EnableHTTPProxy sets the "http_proxy" environment variable -// to the provided proxy string. This enables an HTTP proxy -// for network operations in the current process. -// -// **Parameters:** -// -// proxy: A string representing the URL of the proxy server to be used for HTTP connections. -func EnableHTTPProxy(proxy string) { - os.Setenv("http_proxy", proxy) -} - -// DisableHTTPProxy unsets the "http_proxy" environment variable. -// This disables the HTTP proxy for network operations in the current process. -func DisableHTTPProxy() { - os.Unsetenv("http_proxy") -} diff --git a/pkg/network/proxy_test.go b/pkg/network/proxy_test.go deleted file mode 100644 index 949ad4c0..00000000 --- a/pkg/network/proxy_test.go +++ /dev/null @@ -1,126 +0,0 @@ -/* -Copyright © 2023-present, Meta Platforms, Inc. and affiliates -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -package network_test - -import ( - "os" - "testing" - - "github.com/facebookincubator/ttpforge/pkg/network" -) - -func TestEnableHTTPSProxy(t *testing.T) { - tests := []struct { - name string - proxy string - }{ - { - name: "Enable proxy", - proxy: "http://proxy.example.com:8080", - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - network.EnableHTTPSProxy(tc.proxy) - - httpsProxy, _ := os.LookupEnv("https_proxy") - - if httpsProxy != tc.proxy { - t.Errorf("expected https_proxy to be set to %s, got https_proxy: %s", tc.proxy, httpsProxy) - } - }) - } -} - -func TestDisableHTTPSProxy(t *testing.T) { - tests := []struct { - name string - }{ - { - name: "Disable proxy", - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - network.DisableHTTPSProxy() - - httpsProxy, httpsExists := os.LookupEnv("https_proxy") - - if httpsExists { - t.Errorf("expected https_proxy to be unset, https_proxy: %s", httpsProxy) - } - }) - } -} - -func TestEnableNoProxy(t *testing.T) { - testCases := []struct { - name string - domains string - }{ - { - name: "Single domain", - domains: "example.com", - }, - { - name: "Multiple domains", - domains: "example.com,example.org", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - network.EnableNoProxy(tc.domains) - result := os.Getenv("no_proxy") - if result != tc.domains { - t.Errorf("Expected no_proxy to be set to '%s', but got '%s'", tc.domains, result) - } - }) - } -} - -func TestDisableNoProxy(t *testing.T) { - os.Setenv("no_proxy", "example.com") - network.DisableNoProxy() - result := os.Getenv("no_proxy") - if result != "" { - t.Errorf("Expected no_proxy to be unset, but got '%s'", result) - } -} - -func TestEnableHTTPProxy(t *testing.T) { - proxy := "http://proxy.example.com:8080" - network.EnableHTTPProxy(proxy) - result := os.Getenv("http_proxy") - if result != proxy { - t.Errorf("Expected http_proxy to be set to '%s', but got '%s'", proxy, result) - } -} - -func TestDisableHTTPProxy(t *testing.T) { - os.Setenv("http_proxy", "http://proxy.example.com:8080") - network.DisableHTTPProxy() - result := os.Getenv("http_proxy") - if result != "" { - t.Errorf("Expected http_proxy to be unset, but got '%s'", result) - } -} diff --git a/pkg/outputs/outputs_test.go b/pkg/outputs/outputs_test.go index 373d295f..a4e41c3f 100644 --- a/pkg/outputs/outputs_test.go +++ b/pkg/outputs/outputs_test.go @@ -16,12 +16,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package outputs_test +package outputs import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/outputs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" @@ -62,7 +61,7 @@ func TestJSONFilter(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - var spec outputs.Spec + var spec Spec err := yaml.Unmarshal([]byte(tc.spec), &spec) require.NoError(t, err) @@ -79,24 +78,24 @@ func TestJSONFilter(t *testing.T) { func TestParse(t *testing.T) { input := `{"foo":{"bar":"baz"},"a":"b"}` - specs := map[string]outputs.Spec{ + specs := map[string]Spec{ "first": { - Filters: []outputs.Filter{ - &outputs.JSONFilter{ + Filters: []Filter{ + &JSONFilter{ Path: "foo.bar", }, }, }, "second": { - Filters: []outputs.Filter{ - &outputs.JSONFilter{ + Filters: []Filter{ + &JSONFilter{ Path: "a", }, }, }, } - results, err := outputs.Parse(specs, input) + results, err := Parse(specs, input) require.NoError(t, err) require.Equal(t, 2, len(results), "should have two outputs") assert.Equal(t, "baz", results["first"], "first output should be correct") diff --git a/pkg/preprocess/preprocess_test.go b/pkg/preprocess/preprocess_test.go index 36089157..7b5a8485 100644 --- a/pkg/preprocess/preprocess_test.go +++ b/pkg/preprocess/preprocess_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package preprocess_test +package preprocess import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/preprocess" "github.com/stretchr/testify/require" ) @@ -74,7 +73,7 @@ args: for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - _, err := preprocess.Parse([]byte(tc.ttpStr)) + _, err := Parse([]byte(tc.ttpStr)) if tc.expectError { require.Error(t, err) } else { diff --git a/pkg/repos/repo_test.go b/pkg/repos/repo_test.go index 1b85ba02..b1c60a61 100644 --- a/pkg/repos/repo_test.go +++ b/pkg/repos/repo_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package repos_test +package repos import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/repos" "github.com/facebookincubator/ttpforge/pkg/testutils" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -38,12 +37,12 @@ const ( func makeRepoTestFs(t *testing.T) afero.Fs { fsys, err := testutils.MakeAferoTestFs(map[string][]byte{ - "repos/a/" + repos.RepoConfigFileName: []byte(`ttp_search_paths: ["ttps", "more/ttps"]`), - "repos/a/ttps/foo/bar/baz/wut.yaml": []byte("placeholder"), - "repos/a/more/ttps/absolute/victory.yaml": []byte("placeholder"), - "repos/invalid/" + repos.RepoConfigFileName: []byte("this: is: invalid: yaml"), - "repos/template-only/" + repos.RepoConfigFileName: []byte(`template_search_paths: ["some_templates", "more/templates"]`), - "repos/template-only/some_templates/my_template/ttp.yaml.tpl" + repos.RepoConfigFileName: []byte("placeholder"), + "repos/a/" + RepoConfigFileName: []byte(`ttp_search_paths: ["ttps", "more/ttps"]`), + "repos/a/ttps/foo/bar/baz/wut.yaml": []byte("placeholder"), + "repos/a/more/ttps/absolute/victory.yaml": []byte("placeholder"), + "repos/invalid/" + RepoConfigFileName: []byte("this: is: invalid: yaml"), + "repos/template-only/" + RepoConfigFileName: []byte(`template_search_paths: ["some_templates", "more/templates"]`), + "repos/template-only/some_templates/my_template/ttp.yaml.tpl" + RepoConfigFileName: []byte("placeholder"), }, ) require.NoError(t, err) @@ -54,7 +53,7 @@ func TestFindTTP(t *testing.T) { tests := []struct { name string - spec repos.Spec + spec Spec fsys afero.Fs expectLoadError bool searchType searchType @@ -64,7 +63,7 @@ func TestFindTTP(t *testing.T) { }{ { name: "Valid Repo (TTP Found in First Dir)", - spec: repos.Spec{ + spec: Spec{ Name: "default", Path: "repos/a", }, @@ -75,7 +74,7 @@ func TestFindTTP(t *testing.T) { }, { name: "Valid Repo (TTP Not Found)", - spec: repos.Spec{ + spec: Spec{ Name: "default", Path: "repos/a", }, @@ -86,7 +85,7 @@ func TestFindTTP(t *testing.T) { }, { name: "Valid Repo (TTP Found in Second Dir)", - spec: repos.Spec{ + spec: Spec{ Name: "default", Path: "repos/a", }, @@ -97,7 +96,7 @@ func TestFindTTP(t *testing.T) { }, { name: "Invalid Repo (Corrupt Config)", - spec: repos.Spec{ + spec: Spec{ Name: "bad", Path: "repos/invalid", }, @@ -106,7 +105,7 @@ func TestFindTTP(t *testing.T) { }, { name: "Valid Repo (Template Found in First Dir)", - spec: repos.Spec{ + spec: Spec{ Name: "templates", Path: "repos/template-only", }, @@ -117,7 +116,7 @@ func TestFindTTP(t *testing.T) { }, { name: "Valid Repo (Template Not Found)", - spec: repos.Spec{ + spec: Spec{ Name: "templates", Path: "repos/template-only", }, diff --git a/pkg/repos/repocollection_test.go b/pkg/repos/repocollection_test.go index dc16b373..61ff2e9c 100644 --- a/pkg/repos/repocollection_test.go +++ b/pkg/repos/repocollection_test.go @@ -17,12 +17,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package repos_test +package repos import ( "testing" - "github.com/facebookincubator/ttpforge/pkg/repos" "github.com/facebookincubator/ttpforge/pkg/testutils" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -31,10 +30,10 @@ import ( func makeRepoCollectionTestFs(t *testing.T) afero.Fs { fsys, err := testutils.MakeAferoTestFs(map[string][]byte{ - "repos/a/" + repos.RepoConfigFileName: []byte(`ttp_search_paths: ["ttps", "more/ttps"]`), + "repos/a/" + RepoConfigFileName: []byte(`ttp_search_paths: ["ttps", "more/ttps"]`), "repos/a/ttps/foo/bar/baz/wut.yaml": []byte("placeholder"), "repos/a/more/ttps/absolute/victory.yaml": []byte("placeholder"), - "repos/b/" + repos.RepoConfigFileName: []byte(`ttp_search_paths: ["even/more/ttps"]`), + "repos/b/" + RepoConfigFileName: []byte(`ttp_search_paths: ["even/more/ttps"]`), "repos/b/even/more/ttps/attempt/again.yaml": []byte(`ttp_search_paths: ["even/more/ttps"]`), "not-a-repo/my-ttp.yaml": []byte("placeholder"), }, @@ -48,7 +47,7 @@ func TestResolveTTPRef(t *testing.T) { tests := []struct { name string description string - specs []repos.Spec + specs []Spec fsys afero.Fs expectLoadError bool ttpRef string @@ -58,7 +57,7 @@ func TestResolveTTPRef(t *testing.T) { }{ { name: "Invalid Specs - Empty Name", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -72,7 +71,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid Specs - Empty Path", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -86,7 +85,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid Specs - Same Name", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -101,7 +100,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid Ref - Multiple Separators", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -113,7 +112,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid Ref - Non-Existent Repo", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -125,7 +124,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid Ref - Non-Existent TTP", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -137,7 +136,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Valid TTP Ref (First Repo)", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -150,7 +149,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Valid TTP Ref (Second Repo)", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -167,7 +166,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Valid TTP Path (Not Ref)", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -192,7 +191,7 @@ func TestResolveTTPRef(t *testing.T) { }, { name: "Invalid TTP path (parent directory does not contain config)", - specs: []repos.Spec{ + specs: []Spec{ { Name: "default", Path: "repos/a", @@ -210,7 +209,7 @@ func TestResolveTTPRef(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - rc, err := repos.NewRepoCollection(tc.fsys, tc.specs, "") + rc, err := NewRepoCollection(tc.fsys, tc.specs, "") if tc.expectLoadError { require.Error(t, err) return