~ubuntu-branches/debian/experimental/golang-go-systemd/experimental

« back to all changes in this revision

Viewing changes to dbus/methods_test.go

  • Committer: Package Import Robot
  • Author(s): Tianon Gravi
  • Date: 2014-06-11 19:41:04 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140611194104-ineqr938vh7ewoil
Tags: 2-1
Updated to v2 upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        return conn
37
37
}
38
38
 
 
39
func findFixture(target string, t *testing.T) string {
 
40
        abs, err := filepath.Abs("../fixtures/" + target)
 
41
        if err != nil {
 
42
                t.Fatal(err)
 
43
        }
 
44
        return abs
 
45
}
 
46
 
39
47
func setupUnit(target string, conn *Conn, t *testing.T) {
40
48
        // Blindly stop the unit in case it is running
41
49
        conn.StopUnit(target, "replace")
42
50
 
43
51
        // Blindly remove the symlink in case it exists
44
52
        targetRun := filepath.Join("/run/systemd/system/", target)
45
 
        err := os.Remove(targetRun)
46
 
 
47
 
        // 1. Enable the unit
48
 
        abs, err := filepath.Abs("../fixtures/" + target)
49
 
        if err != nil {
50
 
                t.Fatal(err)
51
 
        }
52
 
 
 
53
        os.Remove(targetRun)
 
54
}
 
55
 
 
56
func linkUnit(target string, conn *Conn, t *testing.T) {
 
57
        abs := findFixture(target, t)
53
58
        fixture := []string{abs}
54
59
 
55
 
        install, changes, err := conn.EnableUnitFiles(fixture, true, true)
 
60
        changes, err := conn.LinkUnitFiles(fixture, true, true)
56
61
        if err != nil {
57
62
                t.Fatal(err)
58
63
        }
59
64
 
60
 
        if install != false {
61
 
                t.Fatal("Install was true")
62
 
        }
63
 
 
64
65
        if len(changes) < 1 {
65
66
                t.Fatalf("Expected one change, got %v", changes)
66
67
        }
67
68
 
68
 
        if changes[0].Filename != targetRun {
 
69
        runPath := filepath.Join("/run/systemd/system/", target)
 
70
        if changes[0].Filename != runPath {
69
71
                t.Fatal("Unexpected target filename")
70
72
        }
71
73
}
76
78
        conn := setupConn(t)
77
79
 
78
80
        setupUnit(target, conn, t)
 
81
        linkUnit(target, conn, t)
79
82
 
80
83
        // 2. Start the unit
81
84
        job, err := conn.StartUnit(target, "replace")
84
87
        }
85
88
 
86
89
        if job != "done" {
87
 
                t.Fatal("Job is not done, %v", job)
 
90
                t.Fatal("Job is not done:", job)
88
91
        }
89
92
 
90
93
        units, err := conn.ListUnits()
130
133
        conn := setupConn(t)
131
134
 
132
135
        setupUnit(target, conn, t)
 
136
        abs := findFixture(target, t)
 
137
        runPath := filepath.Join("/run/systemd/system/", target)
133
138
 
134
 
        abs, err := filepath.Abs("../fixtures/" + target)
 
139
        // 1. Enable the unit
 
140
        install, changes, err := conn.EnableUnitFiles([]string{abs}, true, true)
135
141
        if err != nil {
136
142
                t.Fatal(err)
137
143
        }
138
144
 
139
 
        path := filepath.Join("/run/systemd/system/", target)
 
145
        if install != false {
 
146
                t.Fatal("Install was true")
 
147
        }
 
148
 
 
149
        if len(changes) < 1 {
 
150
                t.Fatalf("Expected one change, got %v", changes)
 
151
        }
 
152
 
 
153
        if changes[0].Filename != runPath {
 
154
                t.Fatal("Unexpected target filename")
 
155
        }
140
156
 
141
157
        // 2. Disable the unit
142
 
        changes, err := conn.DisableUnitFiles([]string{abs}, true)
 
158
        dChanges, err := conn.DisableUnitFiles([]string{abs}, true)
143
159
        if err != nil {
144
160
                t.Fatal(err)
145
161
        }
146
162
 
147
 
        if len(changes) != 1 {
148
 
                t.Fatalf("Changes should include the path, %v", changes)
149
 
        }
150
 
        if changes[0].Filename != path {
151
 
                t.Fatalf("Change should include correct filename, %+v", changes[0])
152
 
        }
153
 
        if changes[0].Destination != "" {
154
 
                t.Fatalf("Change destination should be empty, %+v", changes[0])
 
163
        if len(dChanges) != 1 {
 
164
                t.Fatalf("Changes should include the path, %v", dChanges)
 
165
        }
 
166
        if dChanges[0].Filename != runPath {
 
167
                t.Fatalf("Change should include correct filename, %+v", dChanges[0])
 
168
        }
 
169
        if dChanges[0].Destination != "" {
 
170
                t.Fatalf("Change destination should be empty, %+v", dChanges[0])
155
171
        }
156
172
}
157
173
 
230
246
 
231
247
        value := info["CPUShares"].(uint64)
232
248
        if value != 1023 {
233
 
                t.Fatal("CPUShares of unit is not 1023, %s", value)
 
249
                t.Fatal("CPUShares of unit is not 1023:", value)
234
250
        }
235
251
}
236
252
 
250
266
        }
251
267
 
252
268
        if job != "done" {
253
 
                t.Fatal("Job is not done, %v", job)
 
269
                t.Fatal("Job is not done:", job)
254
270
        }
255
271
 
256
272
        units, err := conn.ListUnits()
295
311
        conn := setupConn(t)
296
312
 
297
313
        setupUnit(target, conn, t)
 
314
        linkUnit(target, conn, t)
298
315
 
299
316
        jobSize := len(conn.jobListener.jobs)
300
317