110 lines
3.0 KiB
Go
110 lines
3.0 KiB
Go
package databricks
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.pengzhan.dev/haopengzhan/hireme/internal/crawler/crawlertest"
|
|
)
|
|
|
|
type roundTripFunc func(req *http.Request) *http.Response
|
|
|
|
func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
return f(req), nil
|
|
}
|
|
|
|
func TestDatabricksCrawler_DiscoverAndFetch(t *testing.T) {
|
|
mockClient := &http.Client{
|
|
Transport: roundTripFunc(func(r *http.Request) *http.Response {
|
|
if strings.HasSuffix(r.URL.Path, "/jobs/5192301") {
|
|
body := `{
|
|
"id": 5192301,
|
|
"title": "Staff Software Engineer - Lakehouse Query Engine",
|
|
"content": "<p>Databricks is creating the world's most performant unified analytics engine.</p>",
|
|
"location": {
|
|
"name": "Bellevue, WA"
|
|
}
|
|
}`
|
|
return &http.Response{
|
|
StatusCode: http.StatusOK,
|
|
Body: io.NopCloser(bytes.NewBufferString(body)),
|
|
Header: make(http.Header),
|
|
}
|
|
}
|
|
|
|
if strings.HasSuffix(r.URL.Path, "/jobs") {
|
|
body := `{
|
|
"jobs": [
|
|
{
|
|
"id": 5192301,
|
|
"title": "Staff Software Engineer - Lakehouse Query Engine",
|
|
"absolute_url": "https://boards.greenhouse.io/databricks/jobs/5192301",
|
|
"location": {
|
|
"name": "Bellevue, WA"
|
|
}
|
|
}
|
|
]
|
|
}`
|
|
return &http.Response{
|
|
StatusCode: http.StatusOK,
|
|
Body: io.NopCloser(bytes.NewBufferString(body)),
|
|
Header: make(http.Header),
|
|
}
|
|
}
|
|
|
|
return &http.Response{
|
|
StatusCode: http.StatusNotFound,
|
|
Body: io.NopCloser(bytes.NewBufferString("not found")),
|
|
Header: make(http.Header),
|
|
}
|
|
}),
|
|
}
|
|
|
|
c := NewDatabricksCrawlerWithClient(mockClient)
|
|
if !c.CanHandle("databricks") {
|
|
t.Errorf("CanHandle should support databricks")
|
|
}
|
|
|
|
discovered, err := c.DiscoverJobs(context.Background(), "https://boards-api.greenhouse.io/v1/boards/databricks/jobs")
|
|
if err != nil {
|
|
t.Fatalf("DiscoverJobs failed: %v", err)
|
|
}
|
|
|
|
if len(discovered) != 1 {
|
|
t.Fatalf("expected 1 discovered job, got %d", len(discovered))
|
|
}
|
|
|
|
if discovered[0].CanonicalID != "databricks:5192301" {
|
|
t.Errorf("unexpected canonical ID: %s", discovered[0].CanonicalID)
|
|
}
|
|
|
|
extracted, err := c.FetchJobDetail(context.Background(), "https://boards.greenhouse.io/databricks/jobs/5192301")
|
|
if err != nil {
|
|
t.Fatalf("FetchJobDetail failed: %v", err)
|
|
}
|
|
|
|
if extracted.Title != "Staff Software Engineer - Lakehouse Query Engine" {
|
|
t.Errorf("unexpected title: %s", extracted.Title)
|
|
}
|
|
if extracted.Company != "Databricks" {
|
|
t.Errorf("unexpected company: %s", extracted.Company)
|
|
}
|
|
if extracted.Location != "Bellevue, WA" {
|
|
t.Errorf("unexpected location: %s", extracted.Location)
|
|
}
|
|
}
|
|
|
|
func TestDatabricksCrawler_LiveIntegration(t *testing.T) {
|
|
crawlertest.RunLiveIntegration(t, crawlertest.LiveTestConfig{
|
|
PlatformName: "Databricks",
|
|
Crawler: NewDatabricksCrawler(),
|
|
TargetURL: "https://boards-api.greenhouse.io/v1/boards/databricks/jobs",
|
|
ExpectedCanonicalPrefix: "databricks:",
|
|
ExpectedCompany: "Databricks",
|
|
})
|
|
}
|