Skip to content

Commit

Permalink
database tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Oct 4, 2023
1 parent 68f25c7 commit c30a6ff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
55 changes: 37 additions & 18 deletions src/cert-generator/tests/pkg/aws/dynamoDB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,51 @@ package tests

import (
"testing"
)

func TestPutItemNilClient(t *testing.T) {

}

func TestPutItemNodynamoDBClient(t *testing.T) {

}

func TestPutItemNoTableName(t *testing.T) {

}

func TestPutItemWithOptions(t *testing.T) {
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/zLukas/CloudTools/src/cert-generator/pkg/aws"
)

var test_table_record = aws.TableRecord{
CaCert: aws.CertItem{PrivateKey: "CAPRIVKEY",
Cert: "CACERT",
},
CeCert: aws.CertItem{PrivateKey: "CEPRIVKEY",
Cert: "CECERT",
},
Name: "sample-table",
CreationDate: "today",
}

func TestPutItemWithConfiguredTable(t *testing.T) {
type WrongDbClient struct{}

func TestPutItemNilClient(t *testing.T) {
test_db := aws.Database{TableName: "test-name"}
err := test_db.PutItem(test_table_record)
if err == nil {
t.Error("err should be error type, got nil")
} else if err.Error() != "database client is nil" {
t.Errorf("err should be \"database client is nil\", got %s", err.Error())
}
}

func TestPutItemFailed(t *testing.T) {
func TestPutItemNodynamoDBClient(t *testing.T) {
test_db := aws.Database{Client: &WrongDbClient{}}
err := test_db.PutItem(test_table_record)
if err == nil {
t.Error("err should be error type, got nil")
} else if err.Error() != "client is not '*DynamoDB' type" {
t.Errorf("err should be \"client is not '*DynamoDB' type\", got %s", err.Error())
}

}

func TestPutItemOk(t *testing.T) {

func TestPutItemNoTableName(t *testing.T) {
test_db := aws.Database{Client: &dynamodb.DynamoDB{}}
err := test_db.PutItem(test_table_record)
if err == nil {
t.Error("err should be error type, got nil")
} else if err.Error() != "no table name provided" {
t.Errorf("err should be \"no table name provided\", got %s", err.Error())
}
}
8 changes: 4 additions & 4 deletions src/cert-generator/tests/pkg/mocks/tls_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import (

var testError error = fmt.Errorf("FAIL")

type x509Mock struct {
type X509Mock struct {
createcertificatesPass bool
parseCertificatePass bool
}

func (x *x509Mock) CreateCertificate(rand io.Reader, template *x509.Certificate, parent *x509.Certificate, pub any, priv any) ([]byte, error) {
func (x *X509Mock) CreateCertificate(rand io.Reader, template *x509.Certificate, parent *x509.Certificate, pub any, priv any) ([]byte, error) {
if x.createcertificatesPass {
return []byte{0xDE, 0xAD, 0xBE, 0xEF}, nil
} else {
return nil, testError
}
}

func (x *x509Mock) ParseCertificate(der []byte) (*x509.Certificate, error) {
func (x *X509Mock) ParseCertificate(der []byte) (*x509.Certificate, error) {
if x.parseCertificatePass {
return &x509.Certificate{}, nil
} else {
return nil, testError
}
}

type pemMock struct {
type PemMock struct {
encodePass bool
decodePass bool
}
Expand Down

0 comments on commit c30a6ff

Please sign in to comment.