@@ -22,6 +22,7 @@ import (
2222 "reflect"
2323 "strings"
2424 "testing"
25+ "time"
2526
2627 kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
2728 porchapi "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
@@ -30,6 +31,7 @@ import (
3031 "github.com/google/go-cmp/cmp"
3132 coreapi "k8s.io/api/core/v1"
3233 apierrors "k8s.io/apimachinery/pkg/api/errors"
34+ "k8s.io/apimachinery/pkg/api/meta"
3335 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3436 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3537 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -1034,6 +1036,71 @@ func (t *PorchSuite) TestPodEvaluator(ctx context.Context) {
10341036 }
10351037}
10361038
1039+ func (t * PorchSuite ) TestRepositoryError (ctx context.Context ) {
1040+ const (
1041+ repositoryName = "repo-with-error"
1042+ )
1043+ t .CreateF (ctx , & configapi.Repository {
1044+ TypeMeta : metav1.TypeMeta {
1045+ Kind : configapi .RepositoryGVK .Kind ,
1046+ APIVersion : configapi .GroupVersion .Identifier (),
1047+ },
1048+ ObjectMeta : metav1.ObjectMeta {
1049+ Name : repositoryName ,
1050+ Namespace : t .namespace ,
1051+ },
1052+ Spec : configapi.RepositorySpec {
1053+ Description : "Repository With Error" ,
1054+ Type : configapi .RepositoryTypeGit ,
1055+ Content : configapi .RepositoryContentPackage ,
1056+ Git : & configapi.GitRepository {
1057+ // Use `incalid` domain: https://www.rfc-editor.org/rfc/rfc6761#section-6.4
1058+ Repo : "https://repo.invalid/repository.git" ,
1059+ },
1060+ },
1061+ })
1062+ t .Cleanup (func () {
1063+ t .DeleteL (ctx , & configapi.Repository {
1064+ ObjectMeta : metav1.ObjectMeta {
1065+ Name : repositoryName ,
1066+ Namespace : t .namespace ,
1067+ },
1068+ })
1069+ })
1070+
1071+ giveUp := time .Now ().Add (60 * time .Second )
1072+
1073+ for {
1074+ if time .Now ().After (giveUp ) {
1075+ t .Errorf ("Timed out waiting for Repository Condition" )
1076+ break
1077+ }
1078+
1079+ time .Sleep (5 * time .Second )
1080+
1081+ var repository configapi.Repository
1082+ t .GetF (ctx , client.ObjectKey {
1083+ Namespace : t .namespace ,
1084+ Name : repositoryName ,
1085+ }, & repository )
1086+
1087+ available := meta .FindStatusCondition (repository .Status .Conditions , configapi .RepositoryReady )
1088+ if available == nil {
1089+ // Condition not yet set
1090+ t .Logf ("Repository condition not yet available" )
1091+ continue
1092+ }
1093+
1094+ if got , want := available .Status , metav1 .ConditionFalse ; got != want {
1095+ t .Errorf ("Repository Available Condition Status; got %q, want %q" , got , want )
1096+ }
1097+ if got , want := available .Reason , configapi .ReasonError ; got != want {
1098+ t .Errorf ("Repository Available Condition Reason: got %q, want %q" , got , want )
1099+ }
1100+ break
1101+ }
1102+ }
1103+
10371104func (t * PorchSuite ) registerGitRepositoryF (ctx context.Context , repo , name string ) {
10381105 t .CreateF (ctx , & configapi.Repository {
10391106 TypeMeta : metav1.TypeMeta {
0 commit comments