Created
February 4, 2026 17:04
-
-
Save HauptJ/d2ac529b35a856afc2e0c76e28ff1c21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fake | |
| import ( | |
| "errors" | |
| "net/http" | |
| "github.com/ktrysmt/go-bitbucket" | |
| ) | |
| type APIResponse[O any] struct { | |
| Output O | |
| Response *bitbucket.Response | |
| Error error | |
| } | |
| type GitVariable interface { | |
| bitbucket.PipelineVariable | |
| } | |
| type extractKey[V GitVariable] func(gv V) string | |
| type extractUuid[V GitVariable] func(gv V) string | |
| func KeyFromPipelineVariable(pv bitbucket.PipelineVariable) string { | |
| return pv.Key | |
| } | |
| func UuidFromPipelineVariable(pv bitbucket.PipelineVariable) string { | |
| return pv.Uuid | |
| } | |
| func make404APIResponse() *bitbucket.Response { | |
| return &bitbucket.Response{ | |
| Response: &http.Response{ | |
| StatusCode: http.StatusNotFound, | |
| }, | |
| } | |
| } | |
| func makeAPIResponse(page, pages int) *bitbucket.Response { | |
| return &bitbucket.Response{ | |
| Response: &http.Response{ | |
| StatusCode: http.StatusOK, | |
| }, | |
| Page: page, | |
| } | |
| } | |
| type BitBucketMockPipelineVariablesClient struct { | |
| GetPipelineVariable func(opt *bitbucket.RepositoryPipelineVariableOptions) (*bitbucket.PipelineVariable, error) | |
| } | |
| func (mc *BitBucketMockPipelineVariablesClient) GetVariable(opt *bitbucket.RepositoryPipelineVariableOptions) (*bitbucket.PipelineVariable, error) { | |
| return mc.GetPipelineVariable(opt) | |
| } | |
| func mockGetVariable[V GitVariable](UuidExtractor extractUuid[V], responses []APIResponse[[]*V]) func(opt bitbucket.RepositoryPipelineVariablesOptions) (*V, *bitbucket.Response, error) { | |
| getCount := -1 | |
| return func(opt *bitbucket.RepositoryPipelineVariableOptions) (*V, *bitbucket.Response, error) { | |
| getCount++ | |
| if getCount > len(responses)-1 { | |
| return nil, make404APIResponse(), errors.New("404 Not Found") | |
| } | |
| var match *V | |
| for _, v := range responses[getCount].Output { | |
| if UuidExtractor(*v) == opt.Uuid { | |
| match = v | |
| } | |
| } | |
| return match, responses[getCount], responses[getCount].Error | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment