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