github.com/ethanhsieh/snapd@v0.0.0-20210615102523-3db9b8e4edc5/progress/progresstest/progresstest.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package progresstest
    21  
    22  import (
    23  	"github.com/snapcore/snapd/progress"
    24  )
    25  
    26  type Meter struct {
    27  	Labels   []string
    28  	Totals   []float64
    29  	Values   []float64
    30  	Written  [][]byte
    31  	Notices  []string
    32  	Finishes int
    33  }
    34  
    35  // interface check
    36  var _ progress.Meter = (*Meter)(nil)
    37  
    38  func (p *Meter) Start(label string, total float64) {
    39  	p.Spin(label)
    40  	p.SetTotal(total)
    41  }
    42  
    43  func (p *Meter) Set(value float64) {
    44  	p.Values = append(p.Values, value)
    45  }
    46  
    47  func (p *Meter) SetTotal(total float64) {
    48  	p.Totals = append(p.Totals, total)
    49  }
    50  
    51  func (p *Meter) Finished() {
    52  	p.Finishes++
    53  }
    54  
    55  func (p *Meter) Spin(label string) {
    56  	p.Labels = append(p.Labels, label)
    57  }
    58  
    59  func (p *Meter) Write(bs []byte) (n int, err error) {
    60  	p.Written = append(p.Written, bs)
    61  	n = len(bs)
    62  
    63  	return
    64  }
    65  
    66  func (p *Meter) Notify(msg string) {
    67  	p.Notices = append(p.Notices, msg)
    68  }