github.com/prebid/prebid-server/v2@v2.18.0/experiment/adscert/inprocesssigner_test.go (about) 1 package adscert 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestInProcessSigner(t *testing.T) { 9 type aTest struct { 10 desc string 11 generateError bool 12 operationStatusOk bool 13 } 14 testCases := []aTest{ 15 { 16 desc: "generate signer error", 17 generateError: true, 18 operationStatusOk: false, 19 }, 20 { 21 desc: "generate valid response without signature operation error", 22 generateError: false, 23 operationStatusOk: true, 24 }, 25 { 26 desc: "generate valid response with signature operation error", 27 generateError: false, 28 operationStatusOk: false, 29 }, 30 } 31 32 for _, test := range testCases { 33 signatory := &MockLocalAuthenticatedConnectionsSignatory{ 34 returnError: test.generateError, 35 operationStatusOk: test.operationStatusOk, 36 } 37 signer := &inProcessSigner{signatory: signatory} 38 signatureMessage, err := signer.Sign("http://test.com", []byte{}) 39 if test.generateError { 40 assert.EqualError(t, err, "Test error", "incorrect error returned for test: %s", test.desc) 41 } else { 42 if test.operationStatusOk { 43 assert.NoError(t, err, "incorrect result for test: %s", test.desc) 44 assert.Equal(t, "Success", signatureMessage, "incorrect message returned for test : %s", test.desc) 45 } else { 46 assert.EqualError(t, err, "error signing request: SIGNATURE_OPERATION_STATUS_UNDEFINED", "incorrect error type returned for test: %s", test.desc) 47 } 48 } 49 } 50 }