github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cloud/buckets/buckets_test.go (about) 1 // +build unit 2 3 package buckets_test 4 5 import ( 6 "net/url" 7 "testing" 8 9 "github.com/olli-ai/jx/v2/pkg/cloud/buckets" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestSplitBucketURL(t *testing.T) { 15 assertSplitBucketURL(t, "s3://foo/my/file", "s3://foo", "my/file") 16 assertSplitBucketURL(t, "gs://mybucket/beer/cheese.txt?param=1234", "gs://mybucket?param=1234", "beer/cheese.txt") 17 18 } 19 20 func assertSplitBucketURL(t *testing.T, inputURL string, expectedBucketURL string, expectedKey string) { 21 u, err := url.Parse(inputURL) 22 require.NoError(t, err, "failed to parse URL %s", inputURL) 23 24 bucketURL, key := buckets.SplitBucketURL(u) 25 26 assert.Equal(t, expectedBucketURL, bucketURL, "for URL %s", inputURL) 27 assert.Equal(t, expectedKey, key, "for URL %s", inputURL) 28 }