fix tests

This commit is contained in:
jay brown
2025-03-19 14:54:21 -07:00
parent 6a584812aa
commit e88d2f4be5
3 changed files with 39 additions and 7 deletions
+2 -1
View File
@@ -70,7 +70,8 @@ func TestGetStartTime(t *testing.T) {
}) })
t.Run("vcs time - invalid format", func(t *testing.T) { t.Run("vcs time - invalid format", func(t *testing.T) {
var tt time.Time var tt time.Time
expectedTime := time.Now().UTC() // to make the test less likely to fail due to non deterministic temporal issues.
expectedTime := time.Now().UTC().Add(-time.Millisecond)
f := getStartTime(&tt, func() (info *debug.BuildInfo, ok bool) { f := getStartTime(&tt, func() (info *debug.BuildInfo, ok bool) {
return &debug.BuildInfo{ return &debug.BuildInfo{
Settings: []debug.BuildSetting{ Settings: []debug.BuildSetting{
+36 -5
View File
@@ -109,7 +109,6 @@ Y9oMsEsKkJZ1hnMvP4JXOa0beJAwOJosFh5kAAs=
name: "Missing local key paths", name: "Missing local key paths",
config: &rbac.AuthConfig{ config: &rbac.AuthConfig{
AuthType: "local", AuthType: "local",
// Missing key paths
}, },
expectError: true, expectError: true,
}, },
@@ -146,8 +145,38 @@ Y9oMsEsKkJZ1hnMvP4JXOa0beJAwOJosFh5kAAs=
// TestAuthConfigInitializeAuthProvider tests the AuthConfig method version of InitializeAuthProvider // TestAuthConfigInitializeAuthProvider tests the AuthConfig method version of InitializeAuthProvider
func TestAuthConfigInitializeAuthProvider(t *testing.T) { func TestAuthConfigInitializeAuthProvider(t *testing.T) {
// Since we can't load invalid keys but want to test the method itself, // Create a temporary directory for test key files
// we'll test the error paths which don't require valid keys tmpDir, err := os.MkdirTemp("", "rbac-test")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer func(path string) {
err := os.RemoveAll(path)
if err != nil {
t.Fatalf("Failed to remove temp dir: %v", err)
}
}(tmpDir)
// Create temporary key files
privateKeyPath := tmpDir + "/private_key.pem"
publicKeyPath := tmpDir + "/public_key.pem"
// Write dummy PEM content to the key files
err = os.WriteFile(privateKeyPath, []byte(`-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA0Gzk05Pbnb12O7O+vCrwY9oMsEsKkJZ1hnMvP4JXOa0beJAw
DgYKAAAAAAAAAAA=
-----END RSA PRIVATE KEY-----`), 0600)
if err != nil {
t.Fatalf("Failed to write private key: %v", err)
}
err = os.WriteFile(publicKeyPath, []byte(`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Gzk05Pbnb12O7O+vCrw
Y9oMsEsKkJZ1hnMvP4JXOa0beJAwOJosFh5kAAs=
-----END PUBLIC KEY-----`), 0600)
if err != nil {
t.Fatalf("Failed to write public key: %v", err)
}
testCases := []struct { testCases := []struct {
name string name string
@@ -155,12 +184,14 @@ func TestAuthConfigInitializeAuthProvider(t *testing.T) {
expectError bool expectError bool
}{ }{
{ {
name: "Missing local key paths", name: "Supplied local key paths",
config: &rbac.AuthConfig{ config: &rbac.AuthConfig{
AuthType: "local", AuthType: "local",
// Missing key paths // Missing key paths
PublicKeyPath: publicKeyPath,
PrivateKeyPath: privateKeyPath,
}, },
expectError: true, expectError: false,
}, },
{ {
name: "Missing Cognito user pool ID", name: "Missing Cognito user pool ID",
+1 -1
View File
@@ -10,7 +10,7 @@ vars:
PKG: "./pkg/..." PKG: "./pkg/..."
CMD: "./cmd/..." CMD: "./cmd/..."
# yamllint disable-line rule:line-length # yamllint disable-line rule:line-length
EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go" EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go|internal/rbac/cognito.go"
includes: includes:
docker: docker: