package query

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestParseS3URI(t *testing.T) {
	bucket, key, err := parseS3URI("s3://my-bucket/path/to/file.csv")
	require.NoError(t, err)
	assert.Equal(t, "my-bucket", bucket)
	assert.Equal(t, "path/to/file.csv", key)

	_, _, err = parseS3URI("https://example.com/x")
	require.Error(t, err)
}

func TestResolveAthenaCSVLocation(t *testing.T) {
	assert.Equal(t,
		"s3://bucket/prefix/qid.csv",
		resolveAthenaCSVLocation("s3://bucket/prefix/", "qid"),
	)
	assert.Equal(t,
		"s3://bucket/prefix/qid.csv",
		resolveAthenaCSVLocation("s3://bucket/prefix", "qid"),
	)
	assert.Equal(t,
		"s3://bucket/prefix/already.csv",
		resolveAthenaCSVLocation("s3://bucket/prefix/already.csv", "qid"),
	)
}
