fix tests
This commit is contained in:
@@ -70,7 +70,8 @@ func TestGetStartTime(t *testing.T) {
|
||||
})
|
||||
t.Run("vcs time - invalid format", func(t *testing.T) {
|
||||
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) {
|
||||
return &debug.BuildInfo{
|
||||
Settings: []debug.BuildSetting{
|
||||
|
||||
@@ -109,7 +109,6 @@ Y9oMsEsKkJZ1hnMvP4JXOa0beJAwOJosFh5kAAs=
|
||||
name: "Missing local key paths",
|
||||
config: &rbac.AuthConfig{
|
||||
AuthType: "local",
|
||||
// Missing key paths
|
||||
},
|
||||
expectError: true,
|
||||
},
|
||||
@@ -146,8 +145,38 @@ Y9oMsEsKkJZ1hnMvP4JXOa0beJAwOJosFh5kAAs=
|
||||
|
||||
// TestAuthConfigInitializeAuthProvider tests the AuthConfig method version of InitializeAuthProvider
|
||||
func TestAuthConfigInitializeAuthProvider(t *testing.T) {
|
||||
// Since we can't load invalid keys but want to test the method itself,
|
||||
// we'll test the error paths which don't require valid keys
|
||||
// Create a temporary directory for test key files
|
||||
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 {
|
||||
name string
|
||||
@@ -155,12 +184,14 @@ func TestAuthConfigInitializeAuthProvider(t *testing.T) {
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "Missing local key paths",
|
||||
name: "Supplied local key paths",
|
||||
config: &rbac.AuthConfig{
|
||||
AuthType: "local",
|
||||
// Missing key paths
|
||||
PublicKeyPath: publicKeyPath,
|
||||
PrivateKeyPath: privateKeyPath,
|
||||
},
|
||||
expectError: true,
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "Missing Cognito user pool ID",
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ vars:
|
||||
PKG: "./pkg/..."
|
||||
CMD: "./cmd/..."
|
||||
# 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:
|
||||
docker:
|
||||
|
||||
Reference in New Issue
Block a user