Explorar el Código

Fix test with gcloud local credentialss

Mariano Cano hace 4 años
padre
commit
b0d24fb801
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      cas/cloudcas/cloudcas_test.go

+ 10 - 1
cas/cloudcas/cloudcas_test.go

@@ -14,6 +14,7 @@ import (
 	"io"
 	"io"
 	"net"
 	"net"
 	"os"
 	"os"
+	"path/filepath"
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
 	"time"
 	"time"
@@ -402,6 +403,14 @@ func TestNew_real(t *testing.T) {
 		})
 		})
 	}
 	}
 
 
+	failDefaultCredentials := true
+	if home, err := os.UserHomeDir(); err == nil {
+		file := filepath.Join(home, ".config", "gcloud", "application_default_credentials.json")
+		if _, err := os.Stat(file); err == nil {
+			failDefaultCredentials = false
+		}
+	}
+
 	type args struct {
 	type args struct {
 		ctx  context.Context
 		ctx  context.Context
 		opts apiv1.Options
 		opts apiv1.Options
@@ -412,7 +421,7 @@ func TestNew_real(t *testing.T) {
 		args     args
 		args     args
 		wantErr  bool
 		wantErr  bool
 	}{
 	}{
-		{"fail default credentials", true, args{context.Background(), apiv1.Options{CertificateAuthority: testAuthorityName}}, true},
+		{"fail default credentials", true, args{context.Background(), apiv1.Options{CertificateAuthority: testAuthorityName}}, failDefaultCredentials},
 		{"fail certificate authority", false, args{context.Background(), apiv1.Options{}}, true},
 		{"fail certificate authority", false, args{context.Background(), apiv1.Options{}}, true},
 		{"fail with credentials", false, args{context.Background(), apiv1.Options{
 		{"fail with credentials", false, args{context.Background(), apiv1.Options{
 			CertificateAuthority: testAuthorityName, CredentialsFile: "testdata/missing.json",
 			CertificateAuthority: testAuthorityName, CredentialsFile: "testdata/missing.json",