@@ -3,12 +3,15 @@ package config
33import (
44 "bytes"
55 "os"
6+ "path"
67 "path/filepath"
78 "testing"
89
910 "github.com/rs/xid"
1011 "github.com/stretchr/testify/require"
1112 "github.com/stretchr/testify/suite"
13+
14+ "gitlab.com/postgres-ai/database-lab/v3/pkg/util"
1215)
1316
1417func TestLoadConfig (t * testing.T ) {
@@ -59,22 +62,28 @@ func (s *ConfigSuite) TearDownTest() {
5962}
6063
6164func (s * ConfigSuite ) TestGenerateNewID () {
62- instanceID , err := LoadInstanceID (s . mountDir )
65+ instanceID , err := LoadInstanceID ()
6366 s .Require ().NoError (err )
6467 s .NotEmpty (instanceID )
6568
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 )
6873 s .Equal (instanceID , string (data ))
6974}
7075
7176func (s * ConfigSuite ) TestLoadInstanceID () {
7277 instanceID := xid .New ().String ()
7378
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 )
7584 s .Require ().NoError (err )
7685
77- instanceID , err = LoadInstanceID (s . mountDir )
78- s .NoError (err )
86+ instanceID , err = LoadInstanceID ()
87+ s .Require (). NoError (err )
7988 s .Equal (instanceID , instanceID )
8089}
0 commit comments