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

Method SetupTest

cmd/incusd/main_test.go:53–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51const daemonTestSuiteDefaultStoragePool string = "testrunPool"
52
53func (s *daemonTestSuite) SetupTest() {
54 tmpdir, err := os.MkdirTemp("", "incus_testrun_")
55 if err != nil {
56 s.T().Errorf("failed to create temp dir: %v", err)
57 }
58
59 s.tmpdir = tmpdir
60
61 err = os.Setenv("INCUS_DIR", s.tmpdir)
62 if err != nil {
63 s.T().Errorf("failed to set INCUS_DIR: %v", err)
64 }
65
66 s.d, err = mockStartDaemon()
67 if err != nil {
68 s.T().Errorf("failed to start daemon: %v", err)
69 }
70
71 // Create default storage pool. Make sure that we don't pass a nil to
72 // the next function.
73 poolConfig := map[string]string{}
74
75 // Create the database entry for the storage pool.
76 poolDescription := fmt.Sprintf("%s storage pool", daemonTestSuiteDefaultStoragePool)
77 _, err = dbStoragePoolCreateAndUpdateCache(context.Background(), s.d.State(), daemonTestSuiteDefaultStoragePool, poolDescription, "mock", poolConfig)
78 if err != nil {
79 s.T().Errorf("failed to create default storage pool: %v", err)
80 }
81
82 rootDev := map[string]string{}
83 rootDev["path"] = "/"
84 rootDev["pool"] = daemonTestSuiteDefaultStoragePool
85 device := cluster.Device{
86 Name: "root",
87 Type: cluster.TypeDisk,
88 Config: rootDev,
89 }
90
91 err = s.d.db.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
92 profile, err := cluster.GetProfile(ctx, tx.Tx(), "default", "default")
93 if err != nil {
94 return err
95 }
96
97 return cluster.UpdateProfileDevices(ctx, tx.Tx(), int64(profile.ID), map[string]cluster.Device{"root": device})
98 })
99 if err != nil {
100 s.T().Errorf("failed to update default profile: %v", err)
101 }
102
103 s.Req = require.New(s.T())
104}
105
106func (s *daemonTestSuite) TearDownTest() {
107 err := s.d.Stop(context.Background(), unix.SIGQUIT)

Callers

nothing calls this directly

Calls 8

GetProfileFunction · 0.92
UpdateProfileDevicesFunction · 0.92
mockStartDaemonFunction · 0.85
ErrorfMethod · 0.80
TxMethod · 0.80
StateMethod · 0.65
TransactionMethod · 0.45

Tested by

no test coverage detected