github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/configstate/configcore/snapshots_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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 configcore_test
    21  
    22  import (
    23  	. "gopkg.in/check.v1"
    24  
    25  	"github.com/snapcore/snapd/overlord/configstate/configcore"
    26  )
    27  
    28  type snapshotsSuite struct {
    29  	configcoreSuite
    30  }
    31  
    32  var _ = Suite(&snapshotsSuite{})
    33  
    34  func (s *snapshotsSuite) TestConfigureAutomaticSnapshotsExpirationHappy(c *C) {
    35  	err := configcore.Run(&mockConf{
    36  		state: s.state,
    37  		conf: map[string]interface{}{
    38  			"snapshots.automatic.retention": "40h",
    39  		},
    40  	})
    41  	c.Assert(err, IsNil)
    42  }
    43  
    44  func (s *snapshotsSuite) TestConfigureAutomaticSnapshotsExpirationTooLow(c *C) {
    45  	err := configcore.Run(&mockConf{
    46  		state: s.state,
    47  		conf: map[string]interface{}{
    48  			"snapshots.automatic.retention": "10m",
    49  		},
    50  	})
    51  	c.Assert(err, ErrorMatches, `snapshots.automatic.retention must be a value greater than 24 hours, or "no" to disable`)
    52  }
    53  
    54  func (s *snapshotsSuite) TestConfigureAutomaticSnapshotsDisable(c *C) {
    55  	err := configcore.Run(&mockConf{
    56  		state: s.state,
    57  		conf: map[string]interface{}{
    58  			"snapshots.automatic.retention": "no",
    59  		},
    60  	})
    61  	c.Assert(err, IsNil)
    62  }
    63  
    64  func (s *refreshSuite) TestConfigureAutomaticSnapshotsExpirationInvalid(c *C) {
    65  	err := configcore.Run(&mockConf{
    66  		state: s.state,
    67  		conf: map[string]interface{}{
    68  			"snapshots.automatic.retention": "invalid",
    69  		},
    70  	})
    71  	c.Assert(err, ErrorMatches, `snapshots.automatic.retention cannot be parsed:.*`)
    72  }