github.com/jenkins-x/jx/v2@v2.1.155/pkg/cloud/gke/storage/bucket_provider_test.go (about) 1 // +build unit 2 3 package storage 4 5 import ( 6 "strings" 7 "testing" 8 9 gke_test "github.com/jenkins-x/jx/v2/pkg/cloud/gke/mocks" 10 "github.com/jenkins-x/jx/v2/pkg/config" 11 "github.com/petergtz/pegomock" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestCreateNewBucketForClusterWithLongClusterNameAndDashAtCharacterSixty(t *testing.T) { 16 p := GKEBucketProvider{ 17 gcloud: gke_test.NewMockGClouder(), 18 Requirements: &config.RequirementsConfig{ 19 Cluster: config.ClusterConfig{ 20 ProjectID: "project", 21 }, 22 }, 23 } 24 25 pegomock.When(p.gcloud.BucketExists(pegomock.AnyString(), pegomock.AnyString())).ThenReturn(true, nil) 26 27 bucketName, err := p.CreateNewBucketForCluster("rrehhhhhhhhhhhhhhhhhhhhhhhhhj3j3k2kwkdkjdbiwabduwabduoawbdb-dbwdbwaoud", "logs") 28 assert.NoError(t, err) 29 assert.NotNil(t, bucketName, "it should always generate a name") 30 assert.False(t, strings.HasSuffix(bucketName, "-"), "the bucket can't end with a dash") 31 } 32 33 func TestCreateNewBucketForClusterWithSmallClusterName(t *testing.T) { 34 p := GKEBucketProvider{ 35 gcloud: gke_test.NewMockGClouder(), 36 Requirements: &config.RequirementsConfig{ 37 Cluster: config.ClusterConfig{ 38 ProjectID: "project", 39 }, 40 }, 41 } 42 43 pegomock.When(p.gcloud.BucketExists(pegomock.AnyString(), pegomock.AnyString())).ThenReturn(true, nil) 44 45 bucketName := createUniqueBucketNameForCluster("cluster") 46 assert.NotNil(t, bucketName, "it should always generate a name") 47 assert.False(t, strings.HasSuffix(bucketName, "-"), "the bucket can't end with a dash") 48 }