1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package mock
17
18import (
19	"context"
20	"fmt"
21	"fotff/pkg"
22	"github.com/sirupsen/logrus"
23	"time"
24)
25
26type Manager struct {
27	pkgCount int
28}
29
30func NewManager() pkg.Manager {
31	return &Manager{}
32}
33
34func (m *Manager) LastIssue(pkg string) (string, error) {
35	ret := fmt.Sprintf("https://testserver.com/issues/%s", pkg)
36	logrus.Infof("LastIssue: mock implementation returns %s", ret)
37	return ret, nil
38}
39
40func (m *Manager) Steps(from, to string) ([]string, error) {
41	var ret = []string{"step1", "step2", "step3"}
42	for i := range ret {
43		ret[i] = fmt.Sprintf("%s-%s-%s", from, to, ret[i])
44	}
45	logrus.Infof("Steps: mock implementation returns %v", ret)
46	return ret, nil
47}
48
49func (m *Manager) GetNewer(cur string) (string, error) {
50	ret := fmt.Sprintf("pkg%d", m.pkgCount)
51	time.Sleep(time.Duration(m.pkgCount) * time.Second)
52	m.pkgCount++
53	logrus.Infof("GetNewer: mock implementation returns %s", ret)
54	return ret, nil
55}
56
57func (m *Manager) Flash(device string, pkg string, ctx context.Context) error {
58	time.Sleep(time.Second)
59	logrus.Infof("Flash: flashing %s to %s, mock implementation returns OK unconditionally", pkg, device)
60	return nil
61}
62
63func (m *Manager) PkgDir(pkg string) string {
64	return pkg
65}
66