Browse Source

Feat: validation for porjectID

William Young 4 years ago
parent
commit
8744a24817
2 changed files with 10 additions and 0 deletions
  1. 4 0
      pkg/provider/gitlab/gitlab.go
  2. 6 0
      pkg/provider/gitlab/gitlab_test.go

+ 4 - 0
pkg/provider/gitlab/gitlab.go

@@ -244,5 +244,9 @@ func (g *Gitlab) ValidateStore(store esv1beta1.GenericStore) error {
 	if err != nil {
 		return err
 	}
+	projectId := gitlabSpec.ProjectID
+	if projectId == "" {
+		return fmt.Errorf("projectID cannot be empty")
+	}
 	return nil
 }

+ 6 - 0
pkg/provider/gitlab/gitlab_test.go

@@ -248,6 +248,7 @@ func TestValidateStore(t *testing.T) {
 							},
 						},
 					},
+					ProjectID: "my-project",
 				},
 			},
 		},
@@ -261,4 +262,9 @@ func TestValidateStore(t *testing.T) {
 	if err != nil {
 		t.Errorf("want nil got err: %v", err)
 	}
+	store.Spec.Provider.Gitlab.ProjectID = ""
+	err = p.ValidateStore(store)
+	if err == nil {
+		t.Errorf("projectId validation: want error got nil")
+	}
 }