MCPcopy
hub / github.com/lxc/incus / TestContainer_ProfilesMulti

Method TestContainer_ProfilesMulti

cmd/incusd/instance_test.go:54–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52}
53
54func (s *containerTestSuite) TestContainer_ProfilesMulti() {
55 // Create an unprivileged profile
56 err := s.d.db.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
57 profile := cluster.Profile{
58 Name: "unprivileged",
59 Description: "unprivileged",
60 Project: "default",
61 }
62
63 id, err := cluster.CreateProfile(ctx, tx.Tx(), profile)
64 if err != nil {
65 return err
66 }
67
68 err = cluster.CreateProfileConfig(ctx, tx.Tx(), id, map[string]string{"security.privileged": "true"})
69 if err != nil {
70 return err
71 }
72
73 return err
74 })
75
76 s.Req.Nil(err, "Failed to create the unprivileged profile.")
77 defer func() {
78 _ = s.d.db.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
79 return cluster.DeleteProfile(ctx, tx.Tx(), "default", "unprivileged")
80 })
81 }()
82
83 var testProfiles []api.Profile
84
85 err = s.d.db.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
86 testProfiles, err = tx.GetProfiles(ctx, "default", []string{"default", "unprivileged"})
87
88 return err
89 })
90 s.Req.Nil(err)
91
92 args := db.InstanceArgs{
93 Type: instancetype.Container,
94 Ephemeral: false,
95 Profiles: testProfiles,
96 Name: "testFoo",
97 }
98
99 c, op, _, err := instance.CreateInternal(s.d.State(), args, nil, true, true, false)
100 s.Req.Nil(err)
101 op.Done(nil)
102 defer func() { _ = c.Delete(true, true) }()
103
104 profiles := c.Profiles()
105 s.Len(
106 profiles,
107 2,
108 "Didn't get both profiles in instanceCreateInternal.",
109 )
110
111 s.True(

Callers

nothing calls this directly

Calls 13

CreateProfileFunction · 0.92
CreateProfileConfigFunction · 0.92
DeleteProfileFunction · 0.92
CreateInternalFunction · 0.92
TxMethod · 0.80
GetProfilesMethod · 0.65
StateMethod · 0.65
DeleteMethod · 0.65
ProfilesMethod · 0.65
IsPrivilegedMethod · 0.65
TransactionMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected