-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BugFix/Enhancements: Command new --count flag incorrectly always set …
…to 5. Various enhancements made (#23) * Fixed a bug where the count value for the new command wasn't generating values passed in with count. Also made the following changes: * Updated go.mod and go.sum packages * Added tests for hash.go, new.go, and compare.go * Added a .gitignore file * Added a test.yaml file to GitHub workflows for running go tests * Added a .run folder with build.run.xml and test.run.xml configuration files for GoLand development * Added README.md files to .run and commands folders * Moved the main.go file into the cmd/toker folder keeping with standard go project folder structure * Moved cobra commands from the cmd folder to the new cli folder * Updated README.md authors list * Update builds in .goreleaser.yml to include the dir option specified to root and the main.go file to be located in ./cmd/toker * Update releaser.yml from v4 to v5 * Finally fixed the goreleaser issue. Getting rid of depreciated property * Updated README.md to include badges. renamed test.yaml to tests.yaml. Renamed Tests to tests --------- Co-authored-by: bt353 <brandon.tassone@yale.edu>
- Loading branch information
Showing
21 changed files
with
376 additions
and
496 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: tests | ||
on: | ||
push: | ||
|
||
jobs: | ||
tests-off: | ||
name: ${{ matrix.os }} - Go v${{ matrix.go-version }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
go-version: | ||
- "1.21.x" | ||
os: | ||
- "ubuntu-latest" | ||
- "macos-latest" | ||
- "windows-latest" | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Go ${{ matrix.go }} | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Test | ||
run: | | ||
go mod tidy -v | ||
go test -cover ./... |
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,27 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# GoLand excludes | ||
.idea/ | ||
|
||
# Generated executable files (dev) | ||
out/ |
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,10 @@ | ||
# .run | ||
|
||
--- | ||
Sharable build/run/test configurations for GoLand | ||
|
||
## Configs | ||
``` | ||
build.run.xml Configuration for building the toker executable | ||
test.run.xml Configuration for building the toker tests executable | ||
``` |
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,14 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="build" type="GoApplicationRunConfiguration" factoryName="Go Application"> | ||
<module name="toker" /> | ||
<working_directory value="$PROJECT_DIR$" /> | ||
<go_parameters value="-o ../../out/toker" /> | ||
<useCustomBuildTags value="true" /> | ||
<kind value="DIRECTORY" /> | ||
<package value="github.com/YaleSpinup/toker" /> | ||
<directory value="$PROJECT_DIR$/cmd/toker" /> | ||
<filePath value="$PROJECT_DIR$/../tokermain.go" /> | ||
<option name="run" value="false" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,12 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="test" type="GoTestRunConfiguration" factoryName="Go Test"> | ||
<module name="toker" /> | ||
<working_directory value="$PROJECT_DIR$" /> | ||
<kind value="PACKAGE" /> | ||
<package value="github.com/YaleSpinup/toker/cli" /> | ||
<directory value="$PROJECT_DIR$" /> | ||
<filePath value="$PROJECT_DIR$" /> | ||
<framework value="gotest" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,15 @@ | ||
# cli | ||
|
||
--- | ||
The files in this package are exclusively cobra cli command hooks and are the entry points to the various commands to be | ||
executed in the command line. | ||
|
||
## Files List & Descriptions | ||
Below are the current cobra command files used in the application and their descriptions | ||
``` | ||
compare.go Compare a password (UUID) with a bcrypt hash | ||
hash.go Encrypts the password using bcrypt | ||
new.go Generate a list of tokens and optionally their encrypted values | ||
root.go Responsible for setting up the viper configuration file for toker | ||
version.go Display toker version information | ||
``` |
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 cli | ||
|
||
import "testing" | ||
|
||
func TestCompareArgsLengthIsValid(t *testing.T) { | ||
test := func(t *testing.T) { | ||
validInputs := [][]string{ | ||
{"5aca0753-9b50-4de6-bcad-6118f6adc1bb", "18b771aa-7ef7-4d76-84ce-b32d7dde7b0f"}, | ||
} | ||
invalidInputs := [][]string{ | ||
{}, | ||
{"e9b93e68-375b-4f32-be5c-d46bcdae3eb5"}, | ||
{ | ||
"8954a500-2477-45f4-8d8f-73b616bd6953", | ||
"af70e31e-d05a-49c0-9aa4-86a61f106c1a", | ||
"d1a116e0-ea75-41ab-b71c-f5ae59263fed", | ||
}, | ||
} | ||
|
||
for _, input := range validInputs { | ||
err := validateArgs(input) | ||
if err != nil { | ||
t.Errorf("validateArgs failed with error: %s. args: %+v", err, input) | ||
} | ||
return | ||
} | ||
|
||
for _, input := range invalidInputs { | ||
err := validateArgs(input) | ||
if err == nil { | ||
t.Errorf("validateArgs passed when it should failed: %s. args: %+v", err, input) | ||
} | ||
return | ||
} | ||
} | ||
|
||
t.Run("provided cost sizes return expected and valid results", test) | ||
} |
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,86 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestHashCostIsValidSize(t *testing.T) { | ||
test := func(t *testing.T) { | ||
validInputs := [][]interface{}{ | ||
{8, []string{"0ebc3ea8-b731-4b78-a0bb-45cb11aa3336"}}, | ||
{22, []string{"6d6fc85d-8a3c-4af3-b515-57e6931bf5eb"}}, | ||
} | ||
invalidInputs := [][]interface{}{ | ||
{3, []string{"a623da14-e1df-409f-887b-488026b7b921"}}, | ||
{32, []string{"7d723ae1-d96f-4e32-a60c-9911a52bc857"}}, | ||
{-1, []string{"ca4bd336-7d27-42e6-9ec7-59fdaec480de"}}, | ||
} | ||
|
||
for _, input := range validInputs { | ||
err := validateCostAndArgs(input[0].(int), input[1].([]string)) | ||
if err != nil { | ||
t.Errorf( | ||
"validateCostAndArgs failed with error: %s. cost: %d, and args: %+v", | ||
err, | ||
input[0].(int), | ||
input[1].([]string), | ||
) | ||
return | ||
} | ||
} | ||
|
||
for _, input := range invalidInputs { | ||
err := validateCostAndArgs(input[0].(int), input[1].([]string)) | ||
if err == nil { | ||
t.Errorf( | ||
"validateCostAndArgs passed when it should failed. cost: %d, and args: %+v", | ||
input[0].(int), | ||
input[1].([]string), | ||
) | ||
return | ||
} | ||
} | ||
} | ||
|
||
t.Run("count sizes provide expected results", test) | ||
} | ||
|
||
func TestHashArgsLengthIsValid(t *testing.T) { | ||
test := func(t *testing.T) { | ||
validInputs := [][]interface{}{ | ||
{30, []string{"5aca0753-9b50-4de6-bcad-6118f6adc1bb"}}, | ||
} | ||
invalidInputs := [][]interface{}{ | ||
{10, []string{}}, | ||
{25, []string{"e9b93e68-375b-4f32-be5c-d46bcdae3eb5", "18b771aa-7ef7-4d76-84ce-b32d7dde7b0f"}}, | ||
} | ||
|
||
for _, input := range validInputs { | ||
err := validateCostAndArgs(input[0].(int), input[1].([]string)) | ||
if err != nil { | ||
t.Errorf( | ||
"validateCostAndArgs failed with error: %s. cost: %d, and args: %+v", | ||
err, | ||
input[0].(int), | ||
input[1].([]string), | ||
) | ||
} | ||
return | ||
} | ||
|
||
for _, input := range invalidInputs { | ||
err := validateCostAndArgs(input[0].(int), input[1].([]string)) | ||
if err == nil { | ||
t.Errorf( | ||
"validateCostAndArgs passed when it should failed: %s, cost: %d, and args: %+v", | ||
err, | ||
input[0].(int), | ||
input[1].([]string), | ||
) | ||
} | ||
return | ||
} | ||
} | ||
|
||
t.Run("args values lengths provide expected results", test) | ||
} |
Oops, something went wrong.