gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/overlord/snapstate/models_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-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 snapstate_test
    21  
    22  import (
    23  	"github.com/snapcore/snapd/asserts"
    24  	"github.com/snapcore/snapd/asserts/assertstest"
    25  	"github.com/snapcore/snapd/snap/snaptest"
    26  )
    27  
    28  func ModelWithBase(baseName string) *asserts.Model {
    29  	return MakeModel(map[string]interface{}{"base": baseName})
    30  }
    31  
    32  func ModelWithKernelTrack(kernelTrack string) *asserts.Model {
    33  	return MakeModel(map[string]interface{}{"kernel": "kernel=" + kernelTrack})
    34  }
    35  
    36  func ModelWithGadgetTrack(gadgetTrack string) *asserts.Model {
    37  	return MakeModel(map[string]interface{}{"gadget": "brand-gadget=" + gadgetTrack})
    38  }
    39  
    40  func DefaultModel() *asserts.Model {
    41  	return MakeModel(nil)
    42  }
    43  
    44  func MakeModel(override map[string]interface{}) *asserts.Model {
    45  	model := map[string]interface{}{
    46  		"type":         "model",
    47  		"authority-id": "brand",
    48  		"series":       "16",
    49  		"brand-id":     "brand",
    50  		"model":        "baz-3000",
    51  		"architecture": "armhf",
    52  		"gadget":       "brand-gadget",
    53  		"kernel":       "kernel",
    54  		"timestamp":    "2018-01-01T08:00:00+00:00",
    55  	}
    56  	return assertstest.FakeAssertion(model, override).(*asserts.Model)
    57  }
    58  
    59  func MakeModel20(gadgetName string, override map[string]interface{}) *asserts.Model {
    60  	model := map[string]interface{}{
    61  		"type":         "model",
    62  		"authority-id": "brand",
    63  		"series":       "16",
    64  		"brand-id":     "brand",
    65  		"model":        "baz-3000",
    66  		"architecture": "armhf",
    67  		"base":         "core20",
    68  		"grade":        "dangerous",
    69  		"timestamp":    "2018-01-01T08:00:00+00:00",
    70  		"snaps": []interface{}{
    71  			map[string]interface{}{
    72  				"name":            "kernel",
    73  				"id":              "kerneldididididididididididididi",
    74  				"type":            "kernel",
    75  				"default-channel": "20",
    76  			},
    77  			map[string]interface{}{
    78  				"name":            gadgetName,
    79  				"id":              snaptest.AssertedSnapID(gadgetName),
    80  				"type":            "gadget",
    81  				"default-channel": "20",
    82  			},
    83  		},
    84  	}
    85  	return assertstest.FakeAssertion(model, override).(*asserts.Model)
    86  }
    87  
    88  func ClassicModel() *asserts.Model {
    89  	headers := map[string]interface{}{
    90  		"type":         "model",
    91  		"authority-id": "brand",
    92  		"series":       "16",
    93  		"brand-id":     "brand",
    94  		"model":        "classicbaz-3000",
    95  		"classic":      "true",
    96  		"timestamp":    "2018-01-01T08:00:00+00:00",
    97  	}
    98  	return assertstest.FakeAssertion(headers).(*asserts.Model)
    99  }