Skip to content

Commit

Permalink
chore: Move all test to proton_test package.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlejeune74 committed Sep 11, 2023
1 parent 0e3a549 commit 32f6191
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 129 deletions.
3 changes: 2 additions & 1 deletion address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package proton_test

import (
"context"
"testing"

"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-proton-api/server"
"github.com/stretchr/testify/require"
"testing"
)

func TestAddress_Types(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions future_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package proton
package proton_test

import (
"math/rand"
"testing"
"time"

"github.com/ProtonMail/gluon/async"
"github.com/ProtonMail/go-proton-api"
"github.com/stretchr/testify/require"
)

func TestFuture(t *testing.T) {
resCh := make(chan int)

NewFuture(async.NoopPanicHandler{}, func() (int, error) {
proton.NewFuture(async.NoopPanicHandler{}, func() (int, error) {
return 42, nil
}).Then(func(res int, err error) {
resCh <- res
Expand All @@ -22,7 +23,7 @@ func TestFuture(t *testing.T) {
}

func TestGroup(t *testing.T) {
group := NewGroup[int](async.NoopPanicHandler{})
group := proton.NewGroup[int](async.NoopPanicHandler{})

for i := 0; i < 10; i++ {
i := i
Expand Down
2 changes: 1 addition & 1 deletion job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newJob[In, Out any](ctx context.Context, req In) *job[In, Out] {
}
}

func (job *job[In, Out]) result() (Out, error) {
func (job *job[In, Out]) Result() (Out, error) {
return <-job.res, <-job.err
}

Expand Down
9 changes: 5 additions & 4 deletions keyring_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package proton
package proton_test

import (
"testing"

"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/gopenpgp/v2/helper"
"github.com/stretchr/testify/require"
Expand All @@ -11,7 +12,7 @@ import (
func TestKeyring_Unlock(t *testing.T) {
r := require.New(t)

newKey := func(id, passphrase string) Key {
newKey := func(id, passphrase string) proton.Key {
arm, err := helper.GenerateKey(id, id+"@email.com", []byte(passphrase), "rsa", 2048)
r.NoError(err)

Expand All @@ -21,14 +22,14 @@ func TestKeyring_Unlock(t *testing.T) {
serial, err := privKey.Serialize()
r.NoError(err)

return Key{
return proton.Key{
ID: id,
PrivateKey: serial,
Active: true,
}
}

keys := Keys{
keys := proton.Keys{
newKey("1", "good_phrase"),
newKey("2", "good_phrase"),
newKey("3", "bad_phrase"),
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proton
package proton_test

import (
"testing"
Expand Down
9 changes: 5 additions & 4 deletions message_encrypt_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proton
package proton_test

import (
"bytes"
Expand All @@ -7,6 +7,7 @@ import (
"testing"

"github.com/ProtonMail/gluon/rfc822"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -27,7 +28,7 @@ This is explicitly typed plain ASCII text.
kr, err := crypto.NewKeyRing(key)
require.NoError(t, err)

encryptedMessage, err := EncryptRFC822(kr, []byte(message))
encryptedMessage, err := proton.EncryptRFC822(kr, []byte(message))
require.NoError(t, err)

section := rfc822.Parse(encryptedMessage)
Expand Down Expand Up @@ -85,7 +86,7 @@ This is the epilogue. It is also to be ignored.
kr, err := crypto.NewKeyRing(key)
require.NoError(t, err)

encryptedMessage, err := EncryptRFC822(kr, []byte(message))
encryptedMessage, err := proton.EncryptRFC822(kr, []byte(message))
require.NoError(t, err)

section := rfc822.Parse(encryptedMessage)
Expand Down Expand Up @@ -167,7 +168,7 @@ SGVsbG8gQXR0YWNobWVudA==
kr, err := crypto.NewKeyRing(key)
require.NoError(t, err)

encryptedMessage, err := EncryptRFC822(kr, []byte(message))
encryptedMessage, err := proton.EncryptRFC822(kr, []byte(message))
require.NoError(t, err)

section := rfc822.Parse(encryptedMessage)
Expand Down
6 changes: 3 additions & 3 deletions message_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Client) ImportMessages(ctx context.Context, addrKR *crypto.KeyRing, wor

return stream.Flatten(parallel.MapStream(
ctx,
stream.FromIterator(iterator.Slice(chunkSized(req, maxImportCount, maxImportSize, func(req ImportReq) int {
stream.FromIterator(iterator.Slice(ChunkSized(req, maxImportCount, maxImportSize, func(req ImportReq) int {
return len(req.Message)
}))),
workers,
Expand Down Expand Up @@ -113,9 +113,9 @@ func (c *Client) importMessages(ctx context.Context, req []ImportReq) ([]ImportR
}), nil
}

// chunkSized splits a slice into chunks of maximum size and length.
// ChunkSized splits a slice into chunks of maximum size and length.
// It is assumed that the size of each element is less than the maximum size.
func chunkSized[T any](vals []T, maxLen, maxSize int, getSize func(T) int) [][]T {
func ChunkSized[T any](vals []T, maxLen, maxSize int, getSize func(T) int) [][]T {
var chunks [][]T

for len(vals) > 0 {
Expand Down
8 changes: 5 additions & 3 deletions message_import_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package proton
package proton_test

import (
"reflect"
"testing"

"github.com/ProtonMail/go-proton-api"
)

func Test_chunkSized(t *testing.T) {
Expand Down Expand Up @@ -51,8 +53,8 @@ func Test_chunkSized(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := chunkSized(tt.args.vals, tt.args.maxLen, tt.args.maxSize, tt.args.getSize); !reflect.DeepEqual(got, tt.want) {
t.Errorf("chunkSized() = %v, want %v", got, tt.want)
if got := proton.ChunkSized(tt.args.vals, tt.args.maxLen, tt.args.maxSize, tt.args.getSize); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ChunkSized() = %v, want %v", got, tt.want)
}
})
}
Expand Down
Loading

0 comments on commit 32f6191

Please sign in to comment.