2023-11-17 12:47:37 +00:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-12-09 12:56:41 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-11-17 12:47:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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" {
|
2024-12-09 12:56:41 +00:00
|
|
|
_, err := w.Write([]byte(`abc`))
|
|
|
|
require.NoError(t, err)
|
2023-11-17 12:47:37 +00:00
|
|
|
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" {
|
2024-12-09 12:56:41 +00:00
|
|
|
_, err := w.Write([]byte(`abc`))
|
|
|
|
require.NoError(t, err)
|
2023-11-17 12:47:37 +00:00
|
|
|
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)
|
|
|
|
}
|