drone/app/services/usage/mocks.go
Enver Biševac db38802e83 feat: [code-2912]: usage service implementation (#3168)
* feat: [code-2912]: rest and ui changes (#3178)

* requested changes
* rest and ui changes
* requested changes
* add midleware to raw and archieve endpoints
* wire fixed
* requested changes
* Merge remote-tracking branch 'origin/main' into eb/code-2912
* added initial values from db
* minor improvements
* requested changes
* remove check for bandwidth
* wiring dep
* improved test
* limits check added
* config added, minor improvements
* usage service implementation
2024-12-20 10:28:47 +00:00

106 lines
2.3 KiB
Go

// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package usage
import (
"context"
"github.com/harness/gitness/types"
)
const (
sampleText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
sampleLength = len(sampleText)
spaceRef = "space1%2fspace2%2fspace3"
)
type mockInterface struct {
SendFunc func(
ctx context.Context,
payload Metric,
) error
}
func (i *mockInterface) Send(
ctx context.Context,
payload Metric,
) error {
return i.SendFunc(ctx, payload)
}
type SpaceStoreMock struct {
FindByRefFn func(
ctx context.Context,
spaceRef string,
) (*types.Space, error)
FindByIDsFn func(
ctx context.Context,
ids ...int64,
) ([]*types.Space, error)
}
func (s *SpaceStoreMock) FindByRef(
ctx context.Context,
spaceRef string,
) (*types.Space, error) {
return s.FindByRefFn(ctx, spaceRef)
}
func (s *SpaceStoreMock) FindByIDs(
ctx context.Context,
ids ...int64,
) ([]*types.Space, error) {
return s.FindByIDsFn(ctx, ids...)
}
type MetricsMock struct {
UpsertOptimisticFn func(ctx context.Context, in *types.UsageMetric) error
GetMetricsFn func(
ctx context.Context,
rootSpaceID int64,
startDate int64,
endDate int64,
) (*types.UsageMetric, error)
ListFn func(
ctx context.Context,
start int64,
end int64,
) ([]types.UsageMetric, error)
}
func (m *MetricsMock) GetMetrics(
ctx context.Context,
rootSpaceID int64,
startDate int64,
endDate int64,
) (*types.UsageMetric, error) {
return m.GetMetricsFn(ctx, rootSpaceID, startDate, endDate)
}
func (m *MetricsMock) UpsertOptimistic(
ctx context.Context,
in *types.UsageMetric,
) error {
return m.UpsertOptimisticFn(ctx, in)
}
func (m *MetricsMock) List(
ctx context.Context,
start int64,
end int64,
) ([]types.UsageMetric, error) {
return m.ListFn(ctx, start, end)
}