databricks-cli/cmd/labs/github/ref_test.go

52 lines
1.3 KiB
Go
Raw Normal View History

package github
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFileFromRef(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/databrickslabs/ucx/main/README.md" {
_, err := w.Write([]byte(`abc`))
require.NoError(t, err)
return
}
t.Logf("Requested: %s", r.URL.Path)
panic("stub required")
}))
defer server.Close()
ctx := context.Background()
ctx = WithUserContentOverride(ctx, server.URL)
raw, err := ReadFileFromRef(ctx, "databrickslabs", "ucx", "main", "README.md")
assert.NoError(t, err)
assert.Equal(t, []byte("abc"), raw)
}
func TestDownloadZipball(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/repos/databrickslabs/ucx/zipball/main" {
_, err := w.Write([]byte(`abc`))
require.NoError(t, err)
return
}
t.Logf("Requested: %s", r.URL.Path)
panic("stub required")
}))
defer server.Close()
ctx := context.Background()
ctx = WithApiOverride(ctx, server.URL)
raw, err := DownloadZipball(ctx, "databrickslabs", "ucx", "main")
assert.NoError(t, err)
assert.Equal(t, []byte("abc"), raw)
}