diff --git a/pkg/config/config.go b/pkg/config/config.go index 5442dd3a..5294bfe9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,6 +11,7 @@ import ( "gopkg.in/yaml.v2" ) +// AppFs hold the file-system abstraction for this package var AppFs = afero.NewOsFs() // Config contains the fields of gebug configuration diff --git a/pkg/input/input.go b/pkg/input/input.go index 310a8442..734dde8f 100644 --- a/pkg/input/input.go +++ b/pkg/input/input.go @@ -1,6 +1,7 @@ package input import ( + "github.com/spf13/afero" "io/ioutil" "os" "path" @@ -12,9 +13,11 @@ import ( "go.uber.org/zap" ) +// AppFs hold the file-system abstraction for this package +var AppFs = afero.NewOsFs() + // ConfigPrompt asks for fields for the configuration type ConfigPrompt interface { - // Run asks for configuration field and saves it in configuration Run() error } diff --git a/pkg/setup/ide.go b/pkg/setup/ide.go index 60f10fd0..11792a90 100644 --- a/pkg/setup/ide.go +++ b/pkg/setup/ide.go @@ -6,8 +6,10 @@ import ( "path" ) +// AppFs hold the file-system abstraction for this package var AppFs = afero.NewOsFs() +// Ide defines the expected behaviour of each IDE that will have a Gebug integration type Ide interface { // Detected tells if the IDE trails were found in the working directory. e.g: `.vscode` or `.idea` directories. Detected() (bool, error) @@ -36,6 +38,7 @@ func (i baseIde) detected(ideDirName string) (bool, error) { return detected, nil } +// SupportedIdes returns a dictionary holds the IDE name along with the corresponding instance func SupportedIdes(workDir string, port int) map[string]Ide { return map[string]Ide{ "Visual Studio Code": &VsCode{baseIde{WorkDir: workDir, DebuggerPort: port}}, diff --git a/pkg/setup/vscode.go b/pkg/setup/vscode.go index 220a5407..e8f1c711 100644 --- a/pkg/setup/vscode.go +++ b/pkg/setup/vscode.go @@ -16,14 +16,17 @@ const ( defaultVsCodeConfVersion = "0.2.0" ) +// VsCode is the 'Visual Studio Code' integration with Gebug type VsCode struct { baseIde } +// Detected tells if the IDE trails were found in the working directory (the `.vscode` directory exists) func (v VsCode) Detected() (bool, error) { return v.detected(vscodeDirName) } +// GebugInstalled tells if Gebug debugger mode was set in the IDE 'launch.json' file func (v VsCode) GebugInstalled() (bool, error) { detected, err := v.Detected() if err != nil { @@ -45,10 +48,12 @@ func (v VsCode) GebugInstalled() (bool, error) { return installed, nil } +// Enable Gebug's debugger configurations by adding the Gebug object from the configurations json in 'launch.json' func (v VsCode) Enable() error { return v.setEnabled(true) } +// Disable Gebug's debugger configurations by removing the Gebug object from the configurations json in 'launch.json' func (v VsCode) Disable() error { return v.setEnabled(false) } diff --git a/pkg/testutil/testutil.go b/pkg/testutil/testutil.go index b536cdcd..487228e3 100644 --- a/pkg/testutil/testutil.go +++ b/pkg/testutil/testutil.go @@ -9,6 +9,8 @@ import ( "testing" ) +// RunTestData runs all the tests resides in the `testdata` directory and their input/golden file has the following prefix +// using the `check` function the caller can easily consume the test file input and compare the actual result with the golden one. func RunTestData(t *testing.T, prefix string, check func(t *testing.T, input, golden *bytes.Buffer)) { baseDir := "./testdata" files, err := ioutil.ReadDir(baseDir) diff --git a/pkg/validate/validation.go b/pkg/validate/validation.go index 6de8ad55..c9bd7af4 100644 --- a/pkg/validate/validation.go +++ b/pkg/validate/validation.go @@ -8,12 +8,15 @@ import ( "github.com/pkg/errors" ) +// Validator defines the behaviour validation behaviour type Validator interface { Validate(string) error } +// NonEmptyValidator checks that the input is not empty after trimming type NonEmptyValidator struct{} +// Validate checks the input and return an error if its invalid func (v NonEmptyValidator) Validate(input string) error { input = strings.TrimSpace(input) if len(input) <= 0 { @@ -23,10 +26,12 @@ func (v NonEmptyValidator) Validate(input string) error { return nil } +// RegexValidator checks that the input matches a pattern after trimming type RegexValidator struct { Pattern string } +// Validate checks the input and return an error if its invalid func (v RegexValidator) Validate(input string) error { input = strings.TrimSpace(input) if len(input) <= 0 { @@ -40,11 +45,13 @@ func (v RegexValidator) Validate(input string) error { return nil } +// NumericRangeValidator checks that the input is a valid number after trimming and its value is between a given range type NumericRangeValidator struct { Min int Max int } +// Validate checks the input and return an error if its invalid func (v NumericRangeValidator) Validate(input string) error { input = strings.TrimSpace(input) if len(input) <= 0 {