Skip to content

Commit

Permalink
Add tests for dashboard URL link
Browse files Browse the repository at this point in the history
Signed-off-by: Jeev B <[email protected]>
  • Loading branch information
jeevb committed Nov 10, 2023
1 parent ac2929e commit 59a7352
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
pluginIOMocks "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/io/mocks"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/k8s"
mocks2 "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/k8s/mocks"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/tasklog"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/utils"
)

Expand Down Expand Up @@ -615,6 +616,8 @@ func newPluginContext() k8s.PluginContext {
},
},
})
taskExecID.OnGetUniqueNodeID().Return("unique-node")
taskExecID.OnGetGeneratedName().Return("generated-name")

tskCtx := &mocks.TaskExecutionMetadata{}
tskCtx.OnGetTaskExecutionID().Return(taskExecID)
Expand Down Expand Up @@ -669,6 +672,59 @@ func TestGetTaskPhase(t *testing.T) {
}
}

func TestGetEventInfo_DashboardURL(t *testing.T) {
pluginCtx := newPluginContext()
testCases := []struct {
name string
rayJob rayv1alpha1.RayJob
dashboardURLTemplate tasklog.TemplateLogPlugin
expectedTaskLogs []*core.TaskLog
}{
{
name: "dashboard URL displayed",
rayJob: rayv1alpha1.RayJob{
Status: rayv1alpha1.RayJobStatus{
DashboardURL: "exists",
JobStatus: rayv1alpha1.JobStatusRunning,
},
},
dashboardURLTemplate: tasklog.TemplateLogPlugin{
DisplayName: "Ray Dashboard",
TemplateURIs: []tasklog.TemplateURI{"http://test/{{.generatedName}}"},
Scheme: tasklog.TemplateSchemeTaskExecution,
},
expectedTaskLogs: []*core.TaskLog{
{
Name: "Ray Dashboard",
Uri: "http://test/generated-name",
},
},
},
{
name: "dashboard URL is not displayed",
rayJob: rayv1alpha1.RayJob{
Status: rayv1alpha1.RayJobStatus{
JobStatus: rayv1alpha1.JobStatusPending,
},
},
dashboardURLTemplate: tasklog.TemplateLogPlugin{
DisplayName: "dummy",
TemplateURIs: []tasklog.TemplateURI{"http://dummy"},
},
expectedTaskLogs: nil,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.NoError(t, SetConfig(&Config{DashboardUrlTemplate: &tc.dashboardURLTemplate}))
ti, err := getEventInfoForRayJob(logs.LogConfig{}, pluginCtx, &tc.rayJob)
assert.NoError(t, err)
assert.Equal(t, tc.expectedTaskLogs, ti.Logs)
})
}
}

func TestGetPropertiesRay(t *testing.T) {
rayJobResourceHandler := rayJobResourceHandler{}
expected := k8s.PluginProperties{}
Expand Down

0 comments on commit 59a7352

Please sign in to comment.