Updated tests to work in more CICD envs
All checks were successful
test / test-default (push) Successful in 59s

This commit is contained in:
2025-09-09 10:14:07 +02:00
parent caa9787770
commit e61ec39f79
3 changed files with 72 additions and 6 deletions

View File

@@ -2,10 +2,12 @@ package secret
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"testing"
"time"
)
type mockProvider struct {
@@ -54,6 +56,30 @@ func testProvider(t *testing.T, p Provider, tests ...testProviderCase) {
}
}
func testCrypter(t *testing.T, p Provider, keyID string) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
vector := []byte("Hello, Gophers! ʕ◔ϖ◔ʔ")
ciphertext, err := Encrypt(ctx, p, keyID, vector)
if err != nil {
t.Error(err)
return
}
plaintext, err := Decrypt(ctx, p, keyID, ciphertext)
if err != nil {
t.Error(err)
return
}
if err = testEqual(vector)(plaintext); err != nil {
t.Error(err)
}
}
func testNotEmpty(v []byte) error {
if len(v) > 0 {
return nil
@@ -74,6 +100,16 @@ func testEqualString(a string) func([]byte) error {
return testEqual([]byte(a))
}
func testInPipeline() bool {
return os.Getenv("CI") != ""
func testInPipeline() (string, bool) {
if os.Getenv("CI") != "" {
switch {
case os.Getenv("GITEA_ACTIONS") != "":
return "gitea", true
case os.Getenv("GITHUB_ACTIONS") != "":
return "github", true
case os.Getenv("CI_RUNNER_ID") != "":
return "gitlab", true
}
}
return "", true
}