github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/seed/internal/validate_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2020 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 internal_test
    21  
    22  import (
    23  	"fmt"
    24  
    25  	. "gopkg.in/check.v1"
    26  
    27  	"github.com/snapcore/snapd/seed/internal"
    28  )
    29  
    30  type validateSuite struct{}
    31  
    32  var _ = Suite(&validateSuite{})
    33  
    34  func (s *validateSuite) TestValidateSeedSystemLabel(c *C) {
    35  	valid := []string{
    36  		"a",
    37  		"ab",
    38  		"a-a",
    39  		"a-123",
    40  		"a-a-a",
    41  		"20191119",
    42  		"foobar",
    43  		"my-system",
    44  		"brand-system-date-1234",
    45  	}
    46  	for _, label := range valid {
    47  		c.Logf("trying valid label: %q", label)
    48  		err := internal.ValidateUC20SeedSystemLabel(label)
    49  		c.Check(err, IsNil)
    50  	}
    51  
    52  	invalid := []string{
    53  		"",
    54  		"/bin",
    55  		"../../bin/bar",
    56  		":invalid:",
    57  		"日本語",
    58  		"-invalid",
    59  		"invalid-",
    60  		"MYSYSTEM",
    61  		"mySystem",
    62  	}
    63  	for _, label := range invalid {
    64  		c.Logf("trying invalid label: %q", label)
    65  		err := internal.ValidateUC20SeedSystemLabel(label)
    66  		c.Check(err, ErrorMatches, fmt.Sprintf("invalid seed system label: %q", label))
    67  	}
    68  }