From a75743ef7d1715ce42f318ea16bf472b002c97cd Mon Sep 17 00:00:00 2001 From: Ben Yanke Date: Fri, 15 Jun 2018 23:29:15 -0500 Subject: [PATCH] starting framework for unit tests --- configbackend.go | 4 ++-- glauth_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 glauth_test.go diff --git a/configbackend.go b/configbackend.go index 2a76495..d73d0fa 100644 --- a/configbackend.go +++ b/configbackend.go @@ -58,7 +58,7 @@ func (h configHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultC } } if !found { - log.Warning(fmt.Sprintf("Bind Error: User %s not found.", user)) + log.Warning(fmt.Sprintf("Bind Error: User %s not found.", userName)) return ldap.LDAPResultInvalidCredentials, nil } // find the group @@ -71,7 +71,7 @@ func (h configHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultC } } if !found { - log.Warning(fmt.Sprintf("Bind Error: Group %s not found.", group)) + log.Warning(fmt.Sprintf("Bind Error: Group %s not found.", groupName)) return ldap.LDAPResultInvalidCredentials, nil } // validate group membership diff --git a/glauth_test.go b/glauth_test.go new file mode 100644 index 0000000..ec467e5 --- /dev/null +++ b/glauth_test.go @@ -0,0 +1,32 @@ +package main + +// Just the beginning of testing - more to be added + +import ( + "testing" +) + +func TestGetVersionString(t *testing.T) { + + // Setup config and check output + LastGitTag = "7" + BuildTime = "20180616_042045Z" + GitCommit = "a9837f3112fc049fd1e9faca6f56d8be1bec91bd" + GitClean = "1" + GitBranch = "dev" + GitTagIsCommit ="0" + + versionOutput := getVersionString() + if versionOutput != "7" { + t.Errorf("Finish writing this test, output was: %s", versionOutput) + } + + // TODO: write these cases + + // Cases to test: + // 1) if GitTagIsCommit=1 - check for release-based strings (this build is release) + // 2) if GitClean=1 - check for "Commit: " as well as value of commit str + // 3) if GitClean=0 - Ensure "Commit: " is NOT there, as well ensure value of commit str is not there + // 4) do additional checks for release behavior, as well as branch name + +}