Skip to content

Commit 6da9352

Browse files
committed
add tests for the nix config
1 parent a4e4272 commit 6da9352

File tree

2 files changed

+804
-4
lines changed

2 files changed

+804
-4
lines changed

internal/config/nixconf.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,26 @@ func (n *NixConfig) readAccessTokens() (map[string]string, error) {
233233
func (n *NixConfig) parseAccessTokensLine(line string) (map[string]string, error) {
234234
tokens := make(map[string]string)
235235

236-
// Remove "access-tokens = " prefix
237-
parts := strings.SplitN(line, "=", 2)
238-
if len(parts) != 2 {
236+
// Find the position of "access-tokens"
237+
idx := strings.Index(line, "access-tokens")
238+
if idx == -1 {
239+
return nil, fmt.Errorf("invalid access-tokens line")
240+
}
241+
242+
// Find the equals sign after "access-tokens"
243+
eqIdx := strings.Index(line[idx:], "=")
244+
if eqIdx == -1 {
239245
return nil, fmt.Errorf("invalid access-tokens line format")
240246
}
247+
eqIdx += idx
248+
249+
// Get the token pairs after the equals sign
250+
tokenPart := strings.TrimSpace(line[eqIdx+1:])
251+
if tokenPart == "" {
252+
return tokens, nil
253+
}
241254

242-
tokenPairs := strings.Fields(parts[1])
255+
tokenPairs := strings.Fields(tokenPart)
243256
for _, pair := range tokenPairs {
244257
hostToken := strings.SplitN(pair, "=", 2)
245258
if len(hostToken) != 2 {

0 commit comments

Comments
 (0)