Skip to content

Commit

Permalink
test: simplify bcrypt test (#11013)
Browse files Browse the repository at this point in the history
* chore: wrap errors with message (#10592) (#10986)

* issue-10592 Wrap errors with message

Signed-off-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Signed-off-by: Apoorva Mahabaleshwara <apoorvambhat@gmail.com>

* issue-10592 remove unwanted error  wrappers

Signed-off-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Signed-off-by: Apoorva Mahabaleshwara <apoorvambhat@gmail.com>

* chore: fix  error wrapper messages

Signed-off-by: Apoorva Mahabaleshwara <apoorvambhat@gmail.com>

Signed-off-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Signed-off-by: Apoorva Mahabaleshwara <apoorvambhat@gmail.com>
Co-authored-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* test: simplify test

Signed-off-by: emirot <nolan.emirot@workday.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* trigger ci

Signed-off-by: emirot <emirot.nolan@gmail.com>

* feat: sort resource list by created_at, add message to AnalysisRun and replicas to ReplicaSet (#10613)

* Misc UI Improvements: sort by created at in resource list view, add message to AnalysisRun and replicas to Replicaset

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>

* Address PR comments

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>

* No underscore needed in created_at. Add space between icon and message in health details for non-controlled resources

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>

* Guard section

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Co-authored-by: Remington Breeze <remington@breeze.software>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* chore: fix e2e (#11005)

* chore: fix e2e

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* more config

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* global

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

Signed-off-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Signed-off-by: Apoorva Mahabaleshwara <apoorvambhat@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: emirot <nolan.emirot@workday.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: apoorvam1 <apoorvambhat@gmail.com>
Co-authored-by: Apoorva Mahabaleshwara <apoorvamahabaleshwara@Apoorvas-MBP.attlocal.net>
Co-authored-by: emirot <nolan.emirot@workday.com>
Co-authored-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Co-authored-by: Remington Breeze <remington@breeze.software>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
7 people committed Oct 21, 2022
1 parent f059d8b commit ba682e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
5 changes: 3 additions & 2 deletions cmd/argocd/commands/bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package commands

import (
"fmt"
"log"

"github.com/spf13/cobra"
"golang.org/x/crypto/bcrypt"
"log"
)

// bcryptCmd represents the bcrypt command
Expand All @@ -22,7 +23,7 @@ func NewBcryptCmd() *cobra.Command {
if err != nil {
log.Fatalf("Failed to genarate bcrypt hash: %v", err)
}
fmt.Println(string(hash))
fmt.Fprint(cmd.OutOrStdout(), string(hash))
},
}

Expand Down
53 changes: 6 additions & 47 deletions cmd/argocd/commands/bcrypt_test.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,22 @@
package commands

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"golang.org/x/crypto/bcrypt"
"io"
"os"
"strings"
"testing"
)

// capture replaces os.Stdout with a writer that buffers any data written
// to os.Stdout. Call the returned function to clean up and get the data
// as a string.
func capture() func() (string, error) {
r, w, err := os.Pipe()
if err != nil {
panic(err)
}

done := make(chan error, 1)

save := os.Stdout
os.Stdout = w

var buf strings.Builder

go func() {
_, err = io.Copy(&buf, r)
err = r.Close()
if err != nil {
return
}
done <- err
}()

return func() (string, error) {
os.Stdout = save
err := w.Close()
if err != nil {
return "", err
}
err = <-done
return buf.String(), err
}
}

func TestGeneratePassword(t *testing.T) {

done := capture()
bcryptCmd := NewBcryptCmd()

bcryptCmd.SetArgs([]string{"--password", "abc"})
output := new(bytes.Buffer)
bcryptCmd.SetOutput(output)
err := bcryptCmd.Execute()
if err != nil {
return
}
capturedOutput, err := done()
assert.NoError(t, err)

err = bcrypt.CompareHashAndPassword([]byte(capturedOutput), []byte("abc"))
err = bcrypt.CompareHashAndPassword(output.Bytes(), []byte("abc"))
assert.NoError(t, err)
}

0 comments on commit ba682e5

Please sign in to comment.