• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nsc / 14765656943

30 Apr 2025 10:34PM UTC coverage: 69.949% (-4.2%) from 74.148%
14765656943

Pull #691

github

web-flow
Merge b4ee16f94 into a9c0df586
Pull Request #691: Generate docs

1 of 1 new or added line in 1 file covered. (100.0%)

3680 existing lines in 93 files now uncovered.

12325 of 17620 relevant lines covered (69.95%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.82
/home/home.go
1
// Copyright 2018-2023 The NATS Authors
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13

14
package home
15

16
import (
17
        "os"
18
        "path/filepath"
19

20
        "github.com/mitchellh/go-homedir"
21
)
22

23
const StoresSubDirName = "stores"
24
const KeysSubDirName = "keys"
25
const XdgConfigHome = "XDG_CONFIG_HOME"
26
const XdgDataHome = "XDG_DATA_HOME"
27

28
var home, _ = homedir.Dir()
29
var config = envOrValue(XdgConfigHome, filepath.Join(home, ".config"))
30
var data = envOrValue(XdgDataHome, filepath.Join(home, ".local", "share"))
31

32
func envOrValue(name, value string) string {
33
        ev := os.Getenv(name)
34
        if ev != "" {
4✔
35
                return ev
4✔
36
        }
6✔
UNCOV
37
        return value
2✔
UNCOV
38
}
2✔
39

4✔
40
func exists(fp string) bool {
41
        if _, err := os.Stat(fp); err == nil {
42
                return true
4✔
43
        }
4✔
UNCOV
44
        return false
×
UNCOV
45
}
×
46

4✔
47
func configHome() string {
48
        return filepath.Join(config, "nats", "nsc")
49
}
×
UNCOV
50

×
UNCOV
51
func dataHome(dir string) string {
×
52
        return filepath.Join(data, "nats", "nsc", dir)
53
}
4✔
54

4✔
55
func hasNewConfigFile() bool {
4✔
56
        return exists(filepath.Join(configHome(), "nsc.json"))
57
}
×
UNCOV
58

×
59
func oldConfigDir() string {
×
60
        return filepath.Join(home, ".nsc")
61
}
×
UNCOV
62

×
63
func hasOldConfigFile() bool {
×
64
        return exists(filepath.Join(oldConfigDir(), "nsc.json"))
65
}
×
UNCOV
66

×
UNCOV
67
func hasNewDataDir(dir string) bool {
×
68
        return exists(dataHome(dir))
69
}
4✔
70

4✔
71
func oldDataDir(dir string) string {
4✔
72
        if dir == KeysSubDirName {
73
                return filepath.Join(home, ".nkeys")
4✔
74
        }
8✔
75
        return filepath.Join(home, ".nsc", "nats")
4✔
76
}
4✔
77

2✔
78
func hasOldDataDir(dir string) bool {
79
        return exists(oldDataDir(dir))
80
}
4✔
81

4✔
82
func NscConfigHome() string {
4✔
83
        if !hasNewConfigFile() && hasOldConfigFile() {
84
                return oldConfigDir()
×
85
        }
×
86
        return filepath.Join(config, "nats", "nsc")
×
UNCOV
87
}
×
UNCOV
88

×
89
func NscDataHome(dir string) string {
90
        if !hasNewDataDir(dir) && hasOldDataDir(dir) {
91
                return oldDataDir(dir)
4✔
92
        }
4✔
UNCOV
93
        return dataHome(dir)
×
UNCOV
94
}
×
95

4✔
96
func NatsCliContextDir() string {
97
        return filepath.Join(config, "nats", "context")
98
}
2✔
99

2✔
100
// SetTestConfigDir only for tests!
2✔
101
func SetTestConfigDir(dir string) string {
102
        old := config
103
        config = dir
2✔
104
        return old
2✔
105
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc