-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3ffd50
commit da17a42
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build !no_cert_auth | ||
// +build !no_cert_auth | ||
|
||
package certificates_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ansible/receptor/pkg/certificates" | ||
) | ||
|
||
func TestInitCA(t *testing.T) { | ||
type args struct { | ||
opts *certificates.CertOptions | ||
certOut string | ||
keyOut string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Positive test", | ||
args: args{ | ||
opts: &certificates.CertOptions{ | ||
CommonName: "Ansible Automation Controller Nodes Mesh", | ||
Bits: 8192, | ||
}, | ||
certOut: "receptor_cert.pem", | ||
keyOut: "receptor_key.pem", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Negative test", | ||
args: args{ | ||
opts: &certificates.CertOptions{ | ||
Bits: -1, | ||
CommonName: "Ansible Automation Controller Nodes Mesh", | ||
}, | ||
certOut: "receptor_cert.pem", | ||
keyOut: "receptor_key.pem", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := certificates.InitCA(tt.args.opts, tt.args.certOut, tt.args.keyOut); (err != nil) != tt.wantErr { | ||
t.Errorf("InitCA() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |