MCPcopy Create free account
hub / github.com/cloudbase/garm / SetupTest

Method SetupTest

database/sql/file_store_test.go:51–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func (s *FileStoreTestSuite) SetupTest() {
52 ctx := context.Background()
53 watcher.InitWatcher(ctx)
54
55 db, err := NewSQLDatabase(context.Background(), garmTesting.GetTestSqliteDBConfig(s.T()))
56 if err != nil {
57 s.FailNow(fmt.Sprintf("failed to create db connection: %s", err))
58 }
59 s.Store = db
60
61 adminCtx := garmTesting.ImpersonateAdminContext(context.Background(), db, s.T())
62 s.adminCtx = adminCtx
63 s.ctx = adminCtx
64
65 // Create test file objects
66 fileObjects := []params.FileObject{}
67
68 // File 1: Small text file with tags
69 content1 := []byte("Hello, World! This is test file 1.")
70 param := params.CreateFileObjectParams{
71 Name: "test-file-1.txt",
72 Size: int64(len(content1)),
73 Tags: []string{"test", "text"},
74 }
75 fileObj1, err := s.Store.CreateFileObject(s.ctx, param, bytes.NewReader(content1))
76 if err != nil {
77 s.FailNow(fmt.Sprintf("failed to create test file 1: %s", err))
78 }
79 fileObjects = append(fileObjects, fileObj1)
80
81 // File 2: Binary-like content with different tags
82 content2 := []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00} // PNG header-like
83 param = params.CreateFileObjectParams{
84 Name: "test-image.png",
85 Size: int64(len(content2)),
86 Tags: []string{"image", "binary"},
87 }
88 fileObj2, err := s.Store.CreateFileObject(s.ctx, param, bytes.NewReader(content2))
89 if err != nil {
90 s.FailNow(fmt.Sprintf("failed to create test file 2: %s", err))
91 }
92 fileObjects = append(fileObjects, fileObj2)
93
94 // File 3: No tags
95 content3 := []byte("File without tags.")
96 param = params.CreateFileObjectParams{
97 Name: "no-tags.txt",
98 Size: int64(len(content3)),
99 Tags: []string{},
100 }
101 fileObj3, err := s.Store.CreateFileObject(s.ctx, param, bytes.NewReader(content3))
102 if err != nil {
103 s.FailNow(fmt.Sprintf("failed to create test file 3: %s", err))
104 }
105 fileObjects = append(fileObjects, fileObj3)
106
107 s.Fixtures = &FileStoreTestFixtures{
108 FileObjects: fileObjects,

Callers

nothing calls this directly

Calls 3

InitWatcherFunction · 0.92
NewSQLDatabaseFunction · 0.85
CreateFileObjectMethod · 0.65

Tested by

no test coverage detected