Skip to content

Commit

Permalink
test: extend certificate test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Nov 7, 2023
1 parent c1c1f1b commit 3e479b2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
34 changes: 33 additions & 1 deletion internal/cmd/certificate/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

func TestCreate(t *testing.T) {
func TestCreateManaged(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

Expand Down Expand Up @@ -47,3 +47,35 @@ func TestCreate(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expOut, out)
}

func TestCreateUploaded(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := CreateCmd.CobraCommand(
context.Background(),
fx.Client,
fx.TokenEnsurer,
fx.ActionWaiter)
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Create(gomock.Any(), hcloud.CertificateCreateOpts{
Name: "test",
Type: hcloud.CertificateTypeUploaded,
Certificate: "certificate file content",
PrivateKey: "key file content",
}).
Return(&hcloud.Certificate{
ID: 123,
Name: "test",
Type: hcloud.CertificateTypeUploaded,
}, nil, nil)

out, err := fx.Run(cmd, []string{"--name", "test", "--key-file", "testdata/key.pem", "--cert-file", "testdata/cert.pem"})

expOut := "Certificate 123 created\n"

assert.NoError(t, err)
assert.Equal(t, expOut, out)
}
12 changes: 12 additions & 0 deletions internal/cmd/certificate/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func TestDescribe(t *testing.T) {
ID: 123,
Type: hcloud.CertificateUsedByRefTypeLoadBalancer,
}},
Status: &hcloud.CertificateStatus{
Error: &hcloud.Error{
Code: hcloud.ErrorCode("cert_error"),
Message: "Certificate error",
},
Issuance: hcloud.CertificateStatusTypeFailed,
Renewal: hcloud.CertificateStatusTypeScheduled,
},
}

fx.Client.CertificateClient.EXPECT().
Expand All @@ -58,6 +66,10 @@ Fingerprint:
Created: %s (%s)
Not valid before: %s (%s)
Not valid after: %s (%s)
Status:
Issuance: failed
Renewal: scheduled
Failure reason: Certificate error
Domain names:
- example.com
Labels:
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/certificate/testdata/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
certificate file content
1 change: 1 addition & 0 deletions internal/cmd/certificate/testdata/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key file content

0 comments on commit 3e479b2

Please sign in to comment.