-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(version): use struct and add tests (#18)
- Loading branch information
1 parent
4729c5b
commit 274a9d5
Showing
3 changed files
with
85 additions
and
9 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
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,47 @@ | ||
package plugin | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/vault/sdk/logical" | ||
"github.com/stretchr/testify/require" | ||
"github.com/thevilledev/vault-plugin-secrets-vercel/internal/version" | ||
) | ||
|
||
func TestPathInfo(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("ValidInfo", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
version.Branch = "main" | ||
version.BuildDate = time.Now().String() | ||
version.Commit = "xyz" | ||
version.CommitDate = time.Now().String() | ||
version.Dirty = "false" | ||
version.Tag = "v0.0.1" | ||
version.Version = "0.0.1" | ||
|
||
ctx := context.Background() | ||
b, storage := newTestBackend(t) | ||
|
||
res, err := b.HandleRequest(ctx, &logical.Request{ | ||
Storage: storage, | ||
Operation: logical.ReadOperation, | ||
Path: pathPatternInfo, | ||
}) | ||
require.NoError(t, err) | ||
|
||
var vi version.VersionInfo | ||
d, err := json.Marshal(res.Data) | ||
require.NoError(t, err) | ||
err = json.Unmarshal(d, &vi) | ||
require.NoError(t, err) | ||
|
||
vn := version.New() | ||
require.Equal(t, *vn, vi) | ||
}) | ||
} |
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