-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-testcontainers
- Loading branch information
Showing
17 changed files
with
161 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/0xERR0R/blocky/log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewValidateCommand creates new command instance | ||
func NewValidateCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "validate", | ||
Args: cobra.NoArgs, | ||
Short: "Validates the configuration", | ||
RunE: validateConfiguration, | ||
} | ||
} | ||
|
||
func validateConfiguration(_ *cobra.Command, _ []string) error { | ||
log.Log().Infof("Validating configuration file: %s", configPath) | ||
|
||
_, err := os.Stat(configPath) | ||
if err != nil && errors.Is(err, os.ErrNotExist) { | ||
return errors.New("configuration path does not exist") | ||
} | ||
|
||
err = initConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Log().Info("Configuration is valid") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/0xERR0R/blocky/helpertest" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Validate command", func() { | ||
var tmpDir *helpertest.TmpFolder | ||
BeforeEach(func() { | ||
tmpDir = helpertest.NewTmpFolder("config") | ||
}) | ||
When("Validate is called with not existing configuration file", func() { | ||
It("should terminate with error", func() { | ||
c := NewRootCommand() | ||
c.SetArgs([]string{"validate", "--config", "/notexisting/path.yaml"}) | ||
|
||
Expect(c.Execute()).Should(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
When("Validate is called with existing valid configuration file", func() { | ||
It("should terminate without error", func() { | ||
cfgFile := tmpDir.CreateStringFile("config.yaml", | ||
"upstreams:", | ||
" groups:", | ||
" default:", | ||
" - 1.1.1.1") | ||
|
||
c := NewRootCommand() | ||
c.SetArgs([]string{"validate", "--config", cfgFile.Path}) | ||
|
||
Expect(c.Execute()).Should(Succeed()) | ||
}) | ||
}) | ||
|
||
When("Validate is called with existing invalid configuration file", func() { | ||
It("should terminate with error", func() { | ||
cfgFile := tmpDir.CreateStringFile("config.yaml", | ||
"upstreams:", | ||
" groups:", | ||
" default:", | ||
" - 1.broken file") | ||
|
||
c := NewRootCommand() | ||
c.SetArgs([]string{"validate", "--config", cfgFile.Path}) | ||
|
||
Expect(c.Execute()).Should(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters