mirror of
https://github.com/rjNemo/go-pass-gen
synced 2026-06-12 13:46:49 +00:00
fix: lint issues
This commit is contained in:
parent
9af2f6486c
commit
d29ad13fed
7 changed files with 18 additions and 18 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// The Length of the generated password.
|
// Length of the generated password.
|
||||||
Length int
|
Length int
|
||||||
// WithNumbers is set to true if the new password must contain numbers.
|
// WithNumbers is set to true if the new password must contain numbers.
|
||||||
WithNumbers bool
|
WithNumbers bool
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/rjNemo/go-pass-gen/passGen"
|
"github.com/rjNemo/go-pass-gen/passgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -20,7 +20,7 @@ var newPasswordCommand = &cobra.Command{Use: "new",
|
||||||
Short: "New Password",
|
Short: "New Password",
|
||||||
Long: "Create a secure password",
|
Long: "Create a secure password",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
pg := passGen.NewPasswordGenerator(passGen.Options{Length: Length, WithNumbers: WithNumbers})
|
pg := passgen.NewPasswordGenerator(passgen.Options{Length: Length, WithNumbers: WithNumbers})
|
||||||
password := pg.NewPassword()
|
password := pg.NewPassword()
|
||||||
display(password)
|
display(password)
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Package cmd defines the command-line interface to passGen
|
// Package cmd defines the command-line interface to passgen
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -9,11 +9,11 @@ import (
|
||||||
|
|
||||||
// rootCommand initializes the command-line interface application.
|
// rootCommand initializes the command-line interface application.
|
||||||
var rootCommand = &cobra.Command{
|
var rootCommand = &cobra.Command{
|
||||||
Use: "passGen",
|
Use: "passgen",
|
||||||
Short: "PassGen",
|
Short: "PassGen",
|
||||||
Long: "Password Generator",
|
Long: "Password Generator",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
display("** passGen – v0.0.1 **\nUse passGen -h for more information")
|
display("** passgen – v0.0.1 **\nUse passgen -h for more information")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package passGen
|
package passgen
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// LOWERCASE characters if latin alphabet
|
// LOWERCASE characters if latin alphabet
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package passGen
|
package passgen
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// Length of the new password
|
// Length of the new password
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Package passGen creates a random password.
|
// Package passgen creates a random password.
|
||||||
package passGen
|
package passgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
package passGen_test
|
package passgen_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rjNemo/go-pass-gen/passGen"
|
"github.com/rjNemo/go-pass-gen/passgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) {
|
func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) {
|
||||||
opts := passGen.Options{
|
opts := passgen.Options{
|
||||||
Length: rand.Intn(12),
|
Length: rand.Intn(12),
|
||||||
}
|
}
|
||||||
pg := passGen.NewPasswordGenerator(opts)
|
pg := passgen.NewPasswordGenerator(opts)
|
||||||
|
|
||||||
if password := pg.NewPassword(); len(password) != opts.Length {
|
if password := pg.NewPassword(); len(password) != opts.Length {
|
||||||
t.Errorf("Expected a password to be %d characters long, got %d", opts.Length, len(password))
|
t.Errorf("Expected a password to be %d characters long, got %d", opts.Length, len(password))
|
||||||
|
|
@ -20,7 +20,7 @@ func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) {
|
func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) {
|
||||||
pg := passGen.NewPasswordGenerator(passGen.Options{})
|
pg := passgen.NewPasswordGenerator(passgen.Options{})
|
||||||
|
|
||||||
if password := pg.NewPassword(); len(password) != 6 {
|
if password := pg.NewPassword(); len(password) != 6 {
|
||||||
t.Errorf("Expected a password to be %d characters long, got %d", 6, len(password))
|
t.Errorf("Expected a password to be %d characters long, got %d", 6, len(password))
|
||||||
|
|
@ -28,10 +28,10 @@ func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratePasswordWithLettersAndNumbers(t *testing.T) {
|
func TestGeneratePasswordWithLettersAndNumbers(t *testing.T) {
|
||||||
opts := passGen.Options{
|
opts := passgen.Options{
|
||||||
WithNumbers: true,
|
WithNumbers: true,
|
||||||
}
|
}
|
||||||
pg := passGen.NewPasswordGenerator(opts)
|
pg := passgen.NewPasswordGenerator(opts)
|
||||||
|
|
||||||
if password := pg.NewPassword(); !containNumbers(password) {
|
if password := pg.NewPassword(); !containNumbers(password) {
|
||||||
t.Errorf("Expected password to contain NUMBERS, got %q", password)
|
t.Errorf("Expected password to contain NUMBERS, got %q", password)
|
||||||
|
|
@ -39,5 +39,5 @@ func TestGeneratePasswordWithLettersAndNumbers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func containNumbers(str string) bool {
|
func containNumbers(str string) bool {
|
||||||
return strings.ContainsAny(str, passGen.NUMBERS)
|
return strings.ContainsAny(str, passgen.NUMBERS)
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue