~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/lxc/lxd/lxd/profiles_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package main
 
2
 
 
3
import (
 
4
        "database/sql"
 
5
        "testing"
 
6
)
 
7
 
 
8
func Test_removing_a_profile_deletes_associated_configuration_entries(t *testing.T) {
 
9
        var db *sql.DB
 
10
        var err error
 
11
 
 
12
        d := &Daemon{}
 
13
        err = initializeDbObject(d, ":memory:")
 
14
        db = d.db
 
15
 
 
16
        // Insert a container and a related profile. Dont't forget that the profile
 
17
        // we insert is profile ID 2 (there is a default profile already).
 
18
        statements := `
 
19
    INSERT INTO containers (name, architecture, type) VALUES ('thename', 1, 1);
 
20
    INSERT INTO profiles (name) VALUES ('theprofile');
 
21
    INSERT INTO containers_profiles (container_id, profile_id) VALUES (1, 2);
 
22
    INSERT INTO profiles_devices (name, profile_id) VALUES ('somename', 2);
 
23
    INSERT INTO profiles_config (key, value, profile_id) VALUES ('thekey', 'thevalue', 2);
 
24
    INSERT INTO profiles_devices_config (profile_device_id, key, value) VALUES (1, 'something', 'boring');`
 
25
 
 
26
        _, err = db.Exec(statements)
 
27
        if err != nil {
 
28
                t.Fatal(err)
 
29
        }
 
30
 
 
31
        // Delete the profile we just created with dbProfileDelete
 
32
        err = dbProfileDelete(db, "theprofile")
 
33
        if err != nil {
 
34
                t.Fatal(err)
 
35
        }
 
36
 
 
37
        // Make sure there are 0 profiles_devices entries left.
 
38
        devices, err := dbDevices(d.db, "theprofile", true)
 
39
        if err != nil {
 
40
                t.Fatal(err)
 
41
        }
 
42
        if len(devices) != 0 {
 
43
                t.Errorf("Deleting a profile didn't delete the related profiles_devices! There are %d left", len(devices))
 
44
        }
 
45
 
 
46
        // Make sure there are 0 profiles_config entries left.
 
47
        config, err := dbProfileConfig(d.db, "theprofile")
 
48
        if err == nil {
 
49
                t.Fatal("found the profile!")
 
50
        }
 
51
 
 
52
        if len(config) != 0 {
 
53
                t.Errorf("Deleting a profile didn't delete the related profiles_config! There are %d left", len(config))
 
54
        }
 
55
}