@@ -3,36 +3,83 @@ package main
33import (
44 "fmt"
55
6- "github.com/opencontainers/runtime-tools/lifecycle"
6+ l "github.com/opencontainers/runtime-tools/lifecycle"
77)
88
9+ func TestDemo () {
10+ runtime := "runc"
11+
12+ type ActionCase struct {
13+ action l.LifecycleAction
14+ args []string
15+ expected bool
16+ }
17+ cases := []struct {
18+ bundle string
19+ id string
20+ actions []ActionCase
21+ }{
22+ {"noexist_bundle" , "1" , []ActionCase {
23+ {action : l .LifecycleCreate , expected : false }},
24+ },
25+ {"exist_bundle" , "1" , []ActionCase {
26+ {action : l .LifecycleCreate , expected : true }},
27+ },
28+ {"exist_bundle" , "1" , []ActionCase {
29+ {action : l .LifecycleCreate , expected : true },
30+ {action : l .LifecycleCreate , expected : false }},
31+ },
32+ {"exist_bundle_run_err" , "1" , []ActionCase {
33+ {action : l .LifecycleCreate , expected : true },
34+ {action : l .LifecycleStart , expected : false }},
35+ },
36+ }
37+ for _ , c := range cases {
38+ //TODO: Prepare c.bundle
39+ lc , _ := l .NewLifecycle (runtime , c .bundle , c .id )
40+ for _ , a := range c .actions {
41+ _ , err := lc .Operate (a .action )
42+ if err != nil && a .expected == true {
43+ fmt .Printf ("Failed in test" )
44+ break
45+ } else if err == nil && a .expected == false {
46+ fmt .Printf ("Failed in test" )
47+ break
48+ }
49+ }
50+
51+ //TODO: Remove it anyway
52+ lc .Operate (l .LifecycleDelete )
53+ }
54+ }
55+
956func main () {
1057 runtime := "runc"
1158 bundle := "bundle"
1259 id := "25"
13- lc , _ := lifecycle .NewLifecycle (runtime , bundle , id )
60+ lc , _ := l .NewLifecycle (runtime , bundle , id )
1461
1562 fmt .Println ("create" )
16- out , err := lc .Operate (lifecycle .LifecycleCreate )
63+ out , err := lc .Operate (l .LifecycleCreate )
1764 fmt .Println (string (out ), err )
1865
1966 fmt .Println ("state" )
20- out , err = lc .Operate (lifecycle .LifecycleState )
67+ out , err = lc .Operate (l .LifecycleState )
2168 fmt .Println (string (out ), err )
2269
2370 fmt .Println ("start" )
24- out , err = lc .Operate (lifecycle .LifecycleStart )
71+ out , err = lc .Operate (l .LifecycleStart )
2572 fmt .Println (string (out ), err )
2673
2774 fmt .Println ("state" )
28- out , _ = lc .Operate (lifecycle .LifecycleState )
75+ out , _ = lc .Operate (l .LifecycleState )
2976 fmt .Println (string (out ))
3077
3178 fmt .Println ("delete" )
32- out , _ = lc .Operate (lifecycle .LifecycleDelete )
79+ out , _ = lc .Operate (l .LifecycleDelete )
3380 fmt .Println (string (out ))
3481
3582 fmt .Println ("state" )
36- out , _ = lc .Operate (lifecycle .LifecycleState )
83+ out , _ = lc .Operate (l .LifecycleState )
3784 fmt .Println (string (out ))
3885}
0 commit comments