From 9389e38d63ac1b42d58cc98288032a902a29c409 Mon Sep 17 00:00:00 2001 From: Javan lacerda Date: Thu, 15 Aug 2024 17:45:13 +0000 Subject: [PATCH] improve tests Signed-off-by: Javan lacerda --- pkg/config/fulcio_config_test.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/config/fulcio_config_test.go b/pkg/config/fulcio_config_test.go index e32bd0455..479c40ac6 100644 --- a/pkg/config/fulcio_config_test.go +++ b/pkg/config/fulcio_config_test.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "testing" ) @@ -68,9 +69,32 @@ func TestLoadFulcioConfig(t *testing.T) { } } - for _, metaIssuer := range fulcioConfig.MetaIssuers { - if metaIssuer.ClientID != "sigstore" { - t.Errorf("expected sigstore, got %s", metaIssuer.ClientID) + for metaIssuerURLRegex := range fulcioConfig.MetaIssuers { + metaIssuerUrl := strings.ReplaceAll(metaIssuerURLRegex, "*", "foo") + got, ok := fulcioConfig.GetIssuer(metaIssuerUrl) + if !ok { + t.Errorf("expected true, got false, %s", metaIssuerUrl) + } + if got.ClientID != "sigstore" { + t.Errorf("expected sigstore, got %s", got.ClientID) + } + if got.IssuerURL != metaIssuerUrl { + t.Errorf("expected %s, got %s", metaIssuerUrl, got.IssuerURL) + } + + if string(got.Type) == "" { + t.Errorf("issuer Type should not be empty") + } + if got.Type == IssuerTypeCIProvider { + if got.CIProvider == "" { + t.Errorf("issuer that is CIProvider field shouldn't be empty when Type is ci-provider") + } + if _, ok := fulcioConfig.CIIssuerMetadata[got.CIProvider]; !ok { + t.Error("issuer with type ci-provider should have the same CI provider name as key for CIIssuerMetadata") + } + } + if _, ok := fulcioConfig.GetIssuer("not_an_issuer"); ok { + t.Error("no error returned from an unconfigured issuer") } } }