From ba767c5f30c2e5faf76834683ff4c4498ea4a577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstr=C3=B6m?= <erik@hedenstroem.com> Date: Sat, 18 May 2024 11:21:44 +0000 Subject: [PATCH] Added test and CI file --- .gitignore | 30 ++++++++++++++++++++++++++++++ .gitlab-ci.yml | 16 ++++++++++++++++ snok_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 snok_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c434ecd --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +### Go template +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +vendor/*/ +.env + +coverage.* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..8ec3c85 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json + +variables: + SECRET_DETECTION_EXCLUDED_PATHS: 'README.md' + +include: + - template: Security/SAST.gitlab-ci.yml + - template: Security/Secret-Detection.gitlab-ci.yml + - project: 'gitlab/templates' + file: 'SonarQube.gitlab-ci.yml' + - project: 'gitlab/templates' + file: 'Go-Library.gitlab-ci.yml' + - project: 'gitlab/templates' + file: 'Debug.gitlab-ci.yml' + rules: + - if: $GITLAB_CI == "false" diff --git a/snok_test.go b/snok_test.go new file mode 100644 index 0000000..63faf25 --- /dev/null +++ b/snok_test.go @@ -0,0 +1,48 @@ +package snok + +import ( + "os" + "testing" + + "github.com/spf13/cobra" +) + +var ct *CommandTest + +func TestMain(m *testing.M) { + ct = NewCommandTest(rootCmd) + ct.AddContainer("Test", mockContainer) + os.Exit(m.Run()) +} + +func TestCmds(t *testing.T) { + ct.Run(t) +} + +func mockContainer(ct *CommandTest, t *testing.T) (err error) { + if os.Getenv("TEST_MESSAGE") == "" { + t.Setenv("TEST_MESSAGE", "testing") + } + return +} + +var rootCmd = &cobra.Command{ + Version: "1.0.0", + Use: "test", + Short: "Root Short", + Long: `Root Long`, + DisableAutoGenTag: true, + SilenceUsage: true, + Annotations: map[string]string{ + "containers": "Vault", + "tests": `[ + { + "name": "Version", + "args": ["--version"], + "output": "^test version \\d+\\.\\d+\\.\\d+$" + } + ]`, + }, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + }, +} -- GitLab