Skip to content

Commit

Permalink
up: store the loaded remote urls and fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 9, 2022
1 parent 1d9e607 commit 9e8b419
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Config struct {
data map[string]interface{}

// loaded config files records
loadedUrls []string
loadedFiles []string
driverNames []string
reloading bool
Expand Down Expand Up @@ -216,6 +217,9 @@ func (c *Config) IsEmpty() bool {
return len(c.data) == 0
}

// LoadedUrls get loaded urls list
func (c *Config) LoadedUrls() []string { return c.loadedUrls }

// LoadedFiles get loaded files name
func (c *Config) LoadedFiles() []string { return c.loadedFiles }

Expand All @@ -233,6 +237,7 @@ func (c *Config) ClearAll() {
c.ClearData()
c.ClearCaches()

c.loadedUrls = []string{}
c.loadedFiles = []string{}
c.opts.Readonly = false
}
Expand All @@ -242,6 +247,7 @@ func (c *Config) ClearData() {
c.fireHook(OnCleanData)

c.data = make(map[string]interface{})
c.loadedUrls = []string{}
c.loadedFiles = []string{}
}

Expand Down
2 changes: 1 addition & 1 deletion load.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Config) LoadRemote(format, url string) (err error) {
if err = c.parseSourceCode(format, bts); err != nil {
return
}
// c.loadedFiles = append(c.loadedFiles, url)
c.loadedUrls = append(c.loadedUrls, url)
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func TestLoadRemote(t *testing.T) {
is.Nil(err)
is.Equal("123", c.String("age", ""))

is.Len(c.LoadedFiles(), 1)
is.Equal(url, c.LoadedFiles()[0])
is.Len(c.LoadedUrls(), 1)
is.Equal(url, c.LoadedUrls()[0])

// load invalid remote data
url1 := "https://raw.githubusercontent.com/gookit/config/master/testdata/json_error.json"
Expand Down

0 comments on commit 9e8b419

Please sign in to comment.