mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
Every command is cd-*: cd, cd-server, cd-repo-server, cd-application-controller, cd-applicationset-controller, cd-cmp-server, cd-commit-server, cd-dex, cd-git-ask-pass, cd-k8s-auth, cd-notification. util/argo is util/cd; util/notification/argocd is util/notification/cd. Preserved deliberately: github.com/argoproj/argocd-example-apps is an EXTERNAL repo used as an e2e fixture, and notifications-engine + pkg/v2 are real dependencies. Renaming a URL we do not own would break the tests. Two bugs I made and caught, both from a careless sed: - s/argo/cd/g turned 'argocd' into 'cdcd' in two directory names - renaming the package declaration left every call site saying argo.X go build ./... exit 0. Co-authored-by: Hanzo Dev <[email protected]>
49 lines
993 B
Go
49 lines
993 B
Go
package commands
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func TestGeneratePassword(t *testing.T) {
|
|
bcryptCmd := NewBcryptCmd()
|
|
bcryptCmd.SetArgs([]string{"--password", "abc"})
|
|
output := new(bytes.Buffer)
|
|
bcryptCmd.SetOut(output)
|
|
err := bcryptCmd.Execute()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = bcrypt.CompareHashAndPassword(output.Bytes(), []byte("abc"))
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestGeneratePasswordWithStdin(t *testing.T) {
|
|
oldStdin := os.Stdin
|
|
defer func() {
|
|
os.Stdin = oldStdin
|
|
}()
|
|
|
|
input := bytes.NewBufferString("abc\n")
|
|
r, w, _ := os.Pipe()
|
|
_, _ = w.Write(input.Bytes())
|
|
w.Close()
|
|
os.Stdin = r
|
|
|
|
bcryptCmd := NewBcryptCmd()
|
|
bcryptCmd.SetArgs([]string{})
|
|
output := new(bytes.Buffer)
|
|
bcryptCmd.SetOut(output)
|
|
|
|
err := bcryptCmd.Execute()
|
|
require.NoError(t, err)
|
|
|
|
err = bcrypt.CompareHashAndPassword(output.Bytes(), []byte("abc"))
|
|
assert.NoError(t, err)
|
|
}
|