Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Created February 4, 2026 17:04
Show Gist options
  • Select an option

  • Save HauptJ/d2ac529b35a856afc2e0c76e28ff1c21 to your computer and use it in GitHub Desktop.

Select an option

Save HauptJ/d2ac529b35a856afc2e0c76e28ff1c21 to your computer and use it in GitHub Desktop.
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