第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 Go 中的 Pact 返回錯(cuò)誤請(qǐng)求 (400, 500)?

如何使用 Go 中的 Pact 返回錯(cuò)誤請(qǐng)求 (400, 500)?

Go
蕭十郎 2022-12-05 16:41:04
我正在我的公司采用 Pact,但在 Golang 上,我們?cè)诨厩闆r下遇到了障礙,即消費(fèi)者作為一個(gè)端點(diǎn)的 2 個(gè)狀態(tài):Given("存在 id 為 1 的產(chǎn)品").Given("ID 為 2 的產(chǎn)品不存在").我們的麻煩在于不存在的情況。消費(fèi)者mockProvider.AddInteraction().            Given("The product with ID 66 doesn't exists").            UponReceiving("a request Product 66").            WithRequest(http.MethodGet, S("/api/v1/product/66")).            WillRespondWith(http.StatusNotFound).供應(yīng)商func TestContract(t *testing.T) {    SetLogLevel("TRACE")    verifier := HTTPVerifier{}    err := verifier.VerifyProvider(t, VerifyRequest{        ProviderBaseURL:            "http://localhost:8080",        Provider:                   "ms.pact-provider-example-for-go",        ProviderVersion:            "example",                                            // os.Getenv("APP_SHA"),        BrokerURL:                  "https://…", // os.Getenv("PACT_BROKER_BASE_URL"),        PublishVerificationResults: false,        StateHandlers: StateHandlers{            "A product with id 1 exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {                …                return response, nil            },            "A product with id 2 doesn't exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {                // ???            },        },    })    require.NoError(t, err)}問題我們?nèi)绾蜗馪roviderStateV3Response地圖界面一樣返回錯(cuò)誤的請(qǐng)求響應(yīng)?
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

StateHandlers不直接更改響應(yīng)(這可能會(huì)影響測(cè)試的有效性),它們的存在是為了修改當(dāng)前測(cè)試的提供者的內(nèi)部狀態(tài)。使用狀態(tài)名稱(以及可選的參數(shù))來確定應(yīng)該配置什么狀態(tài)。


當(dāng)測(cè)試執(zhí)行時(shí),提供者應(yīng)該在適當(dāng)?shù)臓顟B(tài)下執(zhí)行其通常的代碼,并做出相應(yīng)的響應(yīng)。


        StateHandlers: StateHandlers{

            "A product with id 1 exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {

                // modify internal state of the provider, so that product with ID 1 exists in the database

                return response, nil

            },

            "A product with id 2 doesn't exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {

                // modify internal state of the provider, so that product with ID 2 does not exist in the database

            },

        },

存儲(chǔ)庫中有示例,例如https://github.com/pact-foundation/pact-go/blob/master/examples/mux/provider/user_service_test.go#L94-L120。


狀態(tài)是抽象的——它并不暗示狀態(tài)是如何配置的。它可以通過更新數(shù)據(jù)庫或配置存根等多種方式實(shí)現(xiàn)狀態(tài)轉(zhuǎn)換。


查看完整回答
反對(duì) 回復(fù) 2022-12-05
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)