-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
seed/seedwriter: fail early when system seed directory exists #10220
Changes from 6 commits
1393a14
172c590
2abe614
63c1fac
9fe89ff
c338725
7f8665e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2156,8 +2156,9 @@ func (s *writerSuite) TestDownloadedCore20CheckBaseCoreXX(c *C) { | |
{[]interface{}{requiredBaseCore16Ent}, `cannot add snap "required-base-core16" without also adding its base "core16" \(or "core"\) explicitly`}, | ||
} | ||
|
||
s.opts.Label = "20191003" | ||
for _, t := range tests { | ||
baseLabel := "20191003" | ||
for idx, t := range tests { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also remove the dir instead? I don't have a very strong preference but wanted to mention it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using the index as a suffix seems reasonable enough to me |
||
s.opts.Label = fmt.Sprintf("%s%d", baseLabel, idx) | ||
snaps := []interface{}{ | ||
map[string]interface{}{ | ||
"name": "pc-kernel", | ||
|
@@ -2326,7 +2327,7 @@ func (s *writerSuite) TestCore20NonDangerousDisallowedOptionsSnaps(c *C) { | |
|
||
pcFn := s.makeLocalSnap(c, "pc") | ||
|
||
s.opts.Label = "20191107" | ||
baseLabel := "20191107" | ||
|
||
tests := []struct { | ||
optSnap *seedwriter.OptionsSnap | ||
|
@@ -2338,7 +2339,8 @@ func (s *writerSuite) TestCore20NonDangerousDisallowedOptionsSnaps(c *C) { | |
|
||
const expectedErr = `cannot override channels, add devmode snaps, local snaps, or extra snaps with a model of grade higher than dangerous` | ||
|
||
for _, t := range tests { | ||
for idx, t := range tests { | ||
s.opts.Label = fmt.Sprintf("%s%d", baseLabel, idx) | ||
w, err := seedwriter.New(model, s.opts) | ||
c.Assert(err, IsNil) | ||
|
||
|
@@ -3201,3 +3203,36 @@ func (s *writerSuite) TestSeedSnapsWriteMetaCore20SignedLocalAssertedSnaps(c *C) | |
// no options file was created | ||
c.Check(filepath.Join(systemDir, "options.yaml"), testutil.FileAbsent) | ||
} | ||
|
||
func (s *writerSuite) TestSeedSnapsWriteCore20ErrWhenDirExists(c *C) { | ||
model := s.Brands.Model("my-brand", "my-model", map[string]interface{}{ | ||
"display-name": "my model", | ||
"architecture": "amd64", | ||
"base": "core20", | ||
"grade": "signed", | ||
"snaps": []interface{}{ | ||
map[string]interface{}{ | ||
"name": "pc-kernel", | ||
"id": s.AssertedSnapID("pc-kernel"), | ||
"type": "kernel", | ||
"default-channel": "20", | ||
}, | ||
map[string]interface{}{ | ||
"name": "pc", | ||
"id": s.AssertedSnapID("pc"), | ||
"type": "gadget", | ||
"default-channel": "20", | ||
}}, | ||
}) | ||
|
||
err := os.MkdirAll(filepath.Join(s.opts.SeedDir, "systems", "1234"), 0755) | ||
c.Assert(err, IsNil) | ||
s.opts.Label = "1234" | ||
w, err := seedwriter.New(model, s.opts) | ||
c.Assert(err, IsNil) | ||
c.Assert(w, NotNil) | ||
|
||
_, err = w.Start(s.db, s.newFetcher) | ||
c.Assert(err, ErrorMatches, `system "1234" already exists`) | ||
c.Assert(seedwriter.IsErrSytemDirectoryExists(err), Equals, true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error structs need to be called SystemAlreadyExistsError