@@ -3,12 +3,15 @@ package config
3
3
import (
4
4
"bytes"
5
5
"os"
6
+ "path"
6
7
"path/filepath"
7
8
"testing"
8
9
9
10
"github.com/rs/xid"
10
11
"github.com/stretchr/testify/require"
11
12
"github.com/stretchr/testify/suite"
13
+
14
+ "gitlab.com/postgres-ai/database-lab/v3/pkg/util"
12
15
)
13
16
14
17
func TestLoadConfig (t * testing.T ) {
@@ -59,22 +62,28 @@ func (s *ConfigSuite) TearDownTest() {
59
62
}
60
63
61
64
func (s * ConfigSuite ) TestGenerateNewID () {
62
- instanceID , err := LoadInstanceID (s . mountDir )
65
+ instanceID , err := LoadInstanceID ()
63
66
s .Require ().NoError (err )
64
67
s .NotEmpty (instanceID )
65
68
66
- data , err := os .ReadFile (filepath .Join (s .mountDir , "instance_id" ))
67
- s .NoError (err )
69
+ instanceIDPath , err := util .GetMetaPath ("instance_id" )
70
+ s .Require ().NoError (err )
71
+ data , err := os .ReadFile (instanceIDPath )
72
+ s .Require ().NoError (err )
68
73
s .Equal (instanceID , string (data ))
69
74
}
70
75
71
76
func (s * ConfigSuite ) TestLoadInstanceID () {
72
77
instanceID := xid .New ().String ()
73
78
74
- err := os .WriteFile (filepath .Join (s .mountDir , "instance_id" ), []byte (instanceID ), 0600 )
79
+ instanceIDPath , err := util .GetMetaPath ("instance_id" )
80
+ s .Require ().NoError (err )
81
+ err = os .MkdirAll (path .Dir (instanceIDPath ), 0755 )
82
+ s .Require ().NoError (err )
83
+ err = os .WriteFile (instanceIDPath , []byte (instanceID ), 0600 )
75
84
s .Require ().NoError (err )
76
85
77
- instanceID , err = LoadInstanceID (s . mountDir )
78
- s .NoError (err )
86
+ instanceID , err = LoadInstanceID ()
87
+ s .Require (). NoError (err )
79
88
s .Equal (instanceID , instanceID )
80
89
}
0 commit comments