github.com/lovung/GoCleanArchitecture@v0.0.0-20210302152432-50d91fd29f9f/pkg/hasher/password_test.go (about)

     1  package hasher
     2  
     3  import "testing"
     4  
     5  func TestHashAndCheckPassword(t *testing.T) {
     6  	type args struct {
     7  		password string
     8  	}
     9  	tests := []struct {
    10  		name string
    11  		args args
    12  	}{
    13  		{args: args{password: "testpassword"}},
    14  		{args: args{password: "!@#$%^&*()_+"}},
    15  	}
    16  	for _, tt := range tests {
    17  		t.Run(tt.name, func(t *testing.T) {
    18  			got, _ := HashPassword(tt.args.password)
    19  			if ok, _ := CheckPasswordHash(tt.args.password, got); !ok {
    20  				t.Errorf("Got error Hash and Check password hash = %v, password %v", got, tt.args.password)
    21  			}
    22  		})
    23  	}
    24  }
    25  
    26  func BenchmarkHashAndCheckPassword(b *testing.B) {
    27  	type args struct {
    28  		password string
    29  	}
    30  	tests := []struct {
    31  		name string
    32  		args args
    33  	}{
    34  		{args: args{password: "testpassword"}},
    35  		{args: args{password: "!@#$%^&*()_+"}},
    36  	}
    37  	for _, tt := range tests {
    38  		got, _ := HashPassword(tt.args.password)
    39  		if ok, _ := CheckPasswordHash(tt.args.password, got); !ok {
    40  			b.Errorf("Got error Hash and Check password hash = %v, password %v", got, tt.args.password)
    41  		}
    42  	}
    43  }
    44  
    45  func BenchmarkHashPassword(b *testing.B) {
    46  	type args struct {
    47  		password string
    48  	}
    49  	tests := []struct {
    50  		name string
    51  		args args
    52  	}{
    53  		{args: args{password: "testpassword"}},
    54  		{args: args{password: "!@#$%^&*()_+"}},
    55  	}
    56  	for _, tt := range tests {
    57  		HashPassword(tt.args.password)
    58  	}
    59  }