Skip to content

Add unit testing to package templatenamespace#309

Merged
general-kroll-4-life merged 9 commits into
stackql:mainfrom
sanketmp:add-templatenamespace-unit-test
Oct 16, 2023
Merged

Add unit testing to package templatenamespace#309
general-kroll-4-life merged 9 commits into
stackql:mainfrom
sanketmp:add-templatenamespace-unit-test

Conversation

@sanketmp
Copy link
Copy Markdown
Contributor

@sanketmp sanketmp commented Oct 14, 2023

Description

Added unit testing for internal/stackql/templatenamespace package

Type of change

  • Bug fix (non-breaking change to fix a bug).
  • Feature (non-breaking change to add functionality).
  • Breaking change.
  • Other (eg: documentation change).

Issues referenced.

Fixes #277

Evidence

EV

Checklist:

  • A full round of testing has been completed, and there are no test failures as a result of these changes.
  • The changes are covered with functional and/or integration robot testing.
  • The changes work on all supported platforms.
  • Unit tests pass locally, as per the developer guide.
  • Robot tests pass locally, as per the developer guide.
  • Linter passes locally, as per the developer guide.

Variations

Tech Debt

@sanketmp
Copy link
Copy Markdown
Contributor Author

I am new to golang. Please review.

@general-kroll-4-life
Copy link
Copy Markdown
Contributor

@sanketmp the linting check is failing, all else seems ok. You can run the linter locally, as per the developer guide.

@sanketmp
Copy link
Copy Markdown
Contributor Author

sanketmp commented Oct 15, 2023

@sanketmp the linting check is failing, all else seems ok. You can run the linter locally, as per the developer guide.

@general-kroll-4-life it's showing me 404 page after clicking the link.
Capture
Seems like the page has been removed from there.

Edit: Also I have committed the update.

@general-kroll-4-life
Copy link
Copy Markdown
Contributor

@sanketmp sorry here is the correct reference: https://github.com/stackql/stackql/blob/main/docs/developer_guide.md#linting

@sanketmp
Copy link
Copy Markdown
Contributor Author

Hi @general-kroll-4-life I am getting this error.
error
But this will violate another rule: var-naming: don't use an underscore in the package name. right??😥

@general-kroll-4-life
Copy link
Copy Markdown
Contributor

Don't expect that applies to test packages. Try it and see

@sanketmp
Copy link
Copy Markdown
Contributor Author

@general-kroll-4-life I have tried this with an underscore in the package name and it collapses the whole codefile. Also, it does not recognize the NewTemplateNamespaceConfigurator() function. My guess is, it's happening for Windows just as this PR #304 .I could be wrong.

One more thing. I saw both Lint Workflow runs and neither of them have mentioned this issue/error.

@general-kroll-4-life
Copy link
Copy Markdown
Contributor

@sanketmp got the tests to work and linter to pass with a couple of changes. Here below is the output of git diff HEAD

diff --git a/internal/stackql/templatenamespace/template_namespace_configurator_test.go b/internal/stackql/templatenamespace/template_namespace_configurator_test.go
index 29faefdb..917eda27 100644
--- a/internal/stackql/templatenamespace/template_namespace_configurator_test.go
+++ b/internal/stackql/templatenamespace/template_namespace_configurator_test.go
@@ -1,15 +1,17 @@
-package templatenamespace
+package templatenamespace_test
 
 import (
 	"regexp"
 	"testing"
 	"text/template"
+
+	"github.com/stackql/stackql/internal/stackql/templatenamespace"
 )
 
 func TestGetObjectName(t *testing.T) {
 	regex := regexp.MustCompile(`(?P<objectName>\w+)`)
 	templ := template.Must(template.New("test").Parse("{{.objectName}}"))
-	config, err := NewTemplateNamespaceConfigurator(regex, templ)
+	config, err := templatenamespace.NewTemplateNamespaceConfigurator(regex, templ)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -35,7 +37,7 @@ func TestGetObjectName(t *testing.T) {
 func TestRenderTemplate(t *testing.T) {
 	regex := regexp.MustCompile(`(?P<objectName>\w+)`)
 	templete := template.Must(template.New("test").Parse("TestRenderTemplate's {{.objectName}}"))
-	config, err := NewTemplateNamespaceConfigurator(regex, templete)
+	config, err := templatenamespace.NewTemplateNamespaceConfigurator(regex, templete)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -64,7 +66,7 @@ func TestRenderTemplate(t *testing.T) {
 func TestIsAllowed(t *testing.T) {
 	regex := regexp.MustCompile(`(?P<objectName>\w+)`)
 	temp := template.Must(template.New("test").Parse("{{.objectName}}"))
-	conf, e := NewTemplateNamespaceConfigurator(regex, temp)
+	conf, e := templatenamespace.NewTemplateNamespaceConfigurator(regex, temp)
 	if e != nil {
 		t.Fatal(e)
 	}

Please let me know if you need anything further?

@sanketmp
Copy link
Copy Markdown
Contributor Author

Oh right, I hadn't thought of that. Thanks @general-kroll-4-life.
I have updated and committed the changes.
test passed:
test
lint check passed and gave no errors:
lint

Copy link
Copy Markdown
Contributor

@general-kroll-4-life general-kroll-4-life left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanketmp good stuff thank you

@general-kroll-4-life general-kroll-4-life merged commit 558eae4 into stackql:main Oct 16, 2023
@sanketmp
Copy link
Copy Markdown
Contributor Author

Glad I could help🙌

@jeffreyaven
Copy link
Copy Markdown
Member

great job @sanketmp ! can you make sure to give us a ⭐ at https://github.com/stackql/stackql, thanks again!

@sanketmp
Copy link
Copy Markdown
Contributor Author

⭐Starred. 🎉 Thank you @jeffreyaven it was a great experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit testing to package templatenamespace

3 participants