@@ -39,93 +39,16 @@ import (
3939 "github.com/kbase/dts/dtstest"
4040)
4141
42- // runs all tests serially
43- func TestRunner (t * testing.T ) {
44- tester := SerialTests {Test : t }
45- tester .TestStartAndStopTransfers ()
46- //tester.TestStopAndRestartTransfers()
47- }
48-
49- // This runs setup, runs all tests, and does breakdown.
50- func TestMain (m * testing.M ) {
51- var status int
52- setup ()
53- status = m .Run ()
54- breakdown ()
55- os .Exit (status )
56- }
57-
58- // this function gets called at the begіnning of a test session
59- func setup () {
60- dtstest .EnableDebugLogging ()
61-
62- log .Print ("Creating testing directory...\n " )
63- var err error
64- TESTING_DIR , err = os .MkdirTemp (os .TempDir (), "data-transfer-service-tests-" )
65- if err != nil {
66- log .Panicf ("Couldn't create testing directory: %s" , err )
67- }
68- os .Chdir (TESTING_DIR )
69-
70- // read in the config file with SOURCE_ROOT and DESTINATION_ROOT replaced
71- myConfig := strings .ReplaceAll (transfersConfig , "TESTING_DIR" , TESTING_DIR )
72- err = config .Init ([]byte (myConfig ))
73- if err != nil {
74- log .Panicf ("Couldn't initialize configuration: %s" , err )
75- }
76-
77- // create test resources
78- testDescriptors := map [string ]map [string ]any {
79- "file1" : {
80- "id" : "file1" ,
81- "name" : "file1.dat" ,
82- "path" : "dir1/file1.dat" ,
83- "format" : "text" ,
84- "bytes" : 1024 ,
85- "hash" : "d91f97974d06563cab48d4d43a17e08a" ,
86- "endpoint" : "source-endpoint" ,
87- },
88- "file2" : {
89- "id" : "file2" ,
90- "name" : "file2.dat" ,
91- "path" : "dir2/file2.dat" ,
92- "format" : "text" ,
93- "bytes" : 2048 ,
94- "hash" : "d91f9e974d0e563cab48d4d43a17e08a" ,
95- "endpoint" : "source-endpoint" ,
96- },
97- "file3" : {
98- "id" : "file3" ,
99- "name" : "file3.dat" ,
100- "path" : "dir3/file3.dat" ,
101- "format" : "text" ,
102- "bytes" : 4096 ,
103- "hash" : "e91f9e974d0e563cab48d4d43a17e08e" ,
104- "endpoint" : "source-endpoint" ,
105- },
106- }
107-
108- // register test databases/endpoints referred to in config file
109- dtstest .RegisterTestFixturesFromConfig (endpointOptions , testDescriptors )
110-
111- // Create the data and manifest directories
112- os .Mkdir (config .Service .DataDirectory , 0755 )
113- os .Mkdir (config .Service .ManifestDirectory , 0755 )
114- }
42+ // We attach the tests to this type, which runs them one by one.
43+ type TransferTests struct { Test * testing.T }
11544
116- // this function gets called after all tests have been run
117- func breakdown () {
118- if TESTING_DIR != "" {
119- log .Printf ("Deleting testing directory %s...\n " , TESTING_DIR )
120- os .RemoveAll (TESTING_DIR )
121- }
45+ func TestTransfers (t * testing.T ) {
46+ tester := TransferTests {Test : t }
47+ tester .TestStartAndStop ()
48+ //tester.TestStopAndRestartTransfers()
12249}
12350
124- // To run the tests serially, we attach them to a SerialTests type and
125- // have them run by a a single test runner.
126- type SerialTests struct { Test * testing.T }
127-
128- func (t * SerialTests ) TestStartAndStopTransfers () {
51+ func (t * TransferTests ) TestStartAndStop () {
12952 assert := assert .New (t .Test )
13053
13154 assert .False (Running ())
@@ -137,7 +60,7 @@ func (t *SerialTests) TestStartAndStopTransfers() {
13760 assert .False (Running ())
13861}
13962
140- func (t * SerialTests ) TestStopAndRestartTransfers () {
63+ func (t * TransferTests ) TestStopAndRestart () {
14164 /*
14265 assert := assert.New(t.Test)
14366
@@ -175,6 +98,81 @@ func (t *SerialTests) TestStopAndRestartTransfers() {
17598 */
17699}
177100
101+ // This runs setup, runs all tests, and does breakdown.
102+ func TestMain (m * testing.M ) {
103+ var status int
104+ setup ()
105+ status = m .Run ()
106+ breakdown ()
107+ os .Exit (status )
108+ }
109+
110+ // this function gets called at the begіnning of a test session
111+ func setup () {
112+ dtstest .EnableDebugLogging ()
113+
114+ log .Print ("Creating testing directory...\n " )
115+ var err error
116+ TESTING_DIR , err = os .MkdirTemp (os .TempDir (), "data-transfer-service-tests-" )
117+ if err != nil {
118+ log .Panicf ("Couldn't create testing directory: %s" , err )
119+ }
120+ os .Chdir (TESTING_DIR )
121+
122+ // read in the config file with SOURCE_ROOT and DESTINATION_ROOT replaced
123+ myConfig := strings .ReplaceAll (transfersConfig , "TESTING_DIR" , TESTING_DIR )
124+ err = config .Init ([]byte (myConfig ))
125+ if err != nil {
126+ log .Panicf ("Couldn't initialize configuration: %s" , err )
127+ }
128+
129+ // create test resources
130+ testDescriptors := map [string ]map [string ]any {
131+ "file1" : {
132+ "id" : "file1" ,
133+ "name" : "file1.dat" ,
134+ "path" : "dir1/file1.dat" ,
135+ "format" : "text" ,
136+ "bytes" : 1024 ,
137+ "hash" : "d91f97974d06563cab48d4d43a17e08a" ,
138+ "endpoint" : "source-endpoint" ,
139+ },
140+ "file2" : {
141+ "id" : "file2" ,
142+ "name" : "file2.dat" ,
143+ "path" : "dir2/file2.dat" ,
144+ "format" : "text" ,
145+ "bytes" : 2048 ,
146+ "hash" : "d91f9e974d0e563cab48d4d43a17e08a" ,
147+ "endpoint" : "source-endpoint" ,
148+ },
149+ "file3" : {
150+ "id" : "file3" ,
151+ "name" : "file3.dat" ,
152+ "path" : "dir3/file3.dat" ,
153+ "format" : "text" ,
154+ "bytes" : 4096 ,
155+ "hash" : "e91f9e974d0e563cab48d4d43a17e08e" ,
156+ "endpoint" : "source-endpoint" ,
157+ },
158+ }
159+
160+ // register test databases/endpoints referred to in config file
161+ dtstest .RegisterTestFixturesFromConfig (endpointOptions , testDescriptors )
162+
163+ // Create the data and manifest directories
164+ os .Mkdir (config .Service .DataDirectory , 0755 )
165+ os .Mkdir (config .Service .ManifestDirectory , 0755 )
166+ }
167+
168+ // this function gets called after all tests have been run
169+ func breakdown () {
170+ if TESTING_DIR != "" {
171+ log .Printf ("Deleting testing directory %s...\n " , TESTING_DIR )
172+ os .RemoveAll (TESTING_DIR )
173+ }
174+ }
175+
178176// temporary testing directory
179177var TESTING_DIR string
180178
0 commit comments