Pārlūkot izejas kodu

Feat: Added access key test validation

William Young 4 gadi atpakaļ
vecāks
revīzija
5145302f6b
2 mainītis faili ar 22 papildinājumiem un 0 dzēšanām
  1. 6 0
      pkg/provider/gitlab/gitlab.go
  2. 16 0
      pkg/provider/gitlab/gitlab_test.go

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

@@ -244,9 +244,15 @@ 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")
 	}
+
+	key := gitlabSpec.Auth.SecretRef.AccessToken.Key
+	if key == "" {
+		return fmt.Errorf("key cannot be empty")
+	}
 	return nil
 }

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

@@ -257,14 +257,30 @@ func TestValidateStore(t *testing.T) {
 	if err == nil {
 		t.Errorf("want err got nil")
 	}
+
 	store.Spec.Provider.Gitlab.Auth.SecretRef.AccessToken.Namespace = nil
 	err = p.ValidateStore(store)
 	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")
 	}
+
+	store.Spec.Provider.Gitlab.Auth.SecretRef.AccessToken.Key = ""
+	store.Spec.Provider.Gitlab.ProjectID = "project"
+	err = p.ValidateStore(store)
+	if err == nil {
+		t.Errorf("key cannot be empty")
+	}
 }
+
+// func makeSecretStore()store := &esv1beta1.SecretStore{
+// 	Spec: esv1beta1.SecretStoreSpec{
+// 		Provider: &esv1beta1.SecretStoreProvider{
+// 			Gitlab: &esv1beta1.GitlabProvider{
+// 				Auth: esv1beta1.GitlabAuth{
+// 					SecretRef: esv1beta1.GitlabSecretRef{