-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsimple_set_test.go
More file actions
58 lines (46 loc) · 1.37 KB
/
simple_set_test.go
File metadata and controls
58 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// simple_set_test.go: Testing Argus Simple Set Operations
//
// Copyright (c) 2025 AGILira - A. Giordano
// Series: an AGILira fragment
// SPDX-License-Identifier: MPL-2.0
package argus
import (
"testing"
)
func TestSimpleSet(t *testing.T) {
config := NewConfigManager("test").
StringFlag("host", "default", "Host")
// Do not parse any flags
err := config.Parse([]string{})
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
// Default value
if config.GetString("host") != "default" {
t.Errorf("Expected default 'default', got %q", config.GetString("host"))
}
// Set explicit
config.Set("host", "explicit")
// Should take precedence
if config.GetString("host") != "explicit" {
t.Errorf("Expected explicit 'explicit', got %q", config.GetString("host"))
}
}
func TestSetWithFlag(t *testing.T) {
config := NewConfigManager("test").
StringFlag("host", "default", "Host")
// Parse with flag
err := config.Parse([]string{"--host=from-flag"})
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
// Flag's value should take precedence
if config.GetString("host") != "from-flag" {
t.Errorf("Expected from flag 'from-flag', got %q", config.GetString("host"))
}
// Set explicit should take precedence
config.Set("host", "explicit")
if config.GetString("host") != "explicit" {
t.Errorf("Expected explicit 'explicit', got %q", config.GetString("host"))
}
}