76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package coderd
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
|
||
|
|
"github.com/coder/coder/v2/codersdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRewriteChatStartWorkspaceManualUpdateResponse(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
resp codersdk.Response
|
||
|
|
fallbackDetail string
|
||
|
|
wantDetail string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "NoValidationsAndEmptyDetail",
|
||
|
|
resp: codersdk.Response{
|
||
|
|
Message: "missing required parameter",
|
||
|
|
},
|
||
|
|
fallbackDetail: "wrapped missing required parameter",
|
||
|
|
wantDetail: "missing required parameter",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "NoValidationsAndExistingDetail",
|
||
|
|
resp: codersdk.Response{
|
||
|
|
Message: "missing required parameter",
|
||
|
|
Detail: "region must be set before the workspace can start",
|
||
|
|
},
|
||
|
|
fallbackDetail: "wrapped missing required parameter",
|
||
|
|
wantDetail: "missing required parameter: region must be set before the workspace can start",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "ValidationsAndEmptyDetail",
|
||
|
|
resp: codersdk.Response{
|
||
|
|
Message: "missing required parameter",
|
||
|
|
Validations: []codersdk.ValidationError{{
|
||
|
|
Field: "region",
|
||
|
|
Detail: "region must be set before the workspace can start",
|
||
|
|
}},
|
||
|
|
},
|
||
|
|
fallbackDetail: "wrapped missing required parameter",
|
||
|
|
wantDetail: "wrapped missing required parameter",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "ValidationsAndExistingDetail",
|
||
|
|
resp: codersdk.Response{
|
||
|
|
Message: "missing required parameter",
|
||
|
|
Detail: "region must be set before the workspace can start",
|
||
|
|
Validations: []codersdk.ValidationError{{
|
||
|
|
Field: "region",
|
||
|
|
Detail: "region must be set before the workspace can start",
|
||
|
|
}},
|
||
|
|
},
|
||
|
|
fallbackDetail: "wrapped missing required parameter",
|
||
|
|
wantDetail: "region must be set before the workspace can start",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
const retryInstructions = "Use read_template before retrying start_workspace."
|
||
|
|
for _, tt := range tests {
|
||
|
|
tt := tt
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
|
||
|
|
got := rewriteChatStartWorkspaceManualUpdateResponse(tt.resp, tt.fallbackDetail, retryInstructions)
|
||
|
|
require.Equal(t, retryInstructions, got.Message)
|
||
|
|
require.Equal(t, tt.wantDetail, got.Detail)
|
||
|
|
require.Equal(t, tt.resp.Validations, got.Validations)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|