-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
43 lines (37 loc) · 952 Bytes
/
config_test.go
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
package main
import (
"os"
"testing"
)
func TestWriteAndReadConfig(t *testing.T) {
// Create a temporary test file
tempFile, err := os.CreateTemp("", "test_snappass_")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
}
defer func() {
// Clean up after the test
err := clear(tempFile.Name())
if err != nil {
t.Errorf("Error removing test file: %v", err)
}
}()
// Test data
testConfig := &Config{
BaseUrl: "https://example.com",
}
// Write the test data to the test file
err = write(tempFile.Name(), testConfig)
if err != nil {
t.Errorf("Error writing config: %v", err)
}
// Read the data back from the test file
readConfig, err := read(tempFile.Name())
if err != nil {
t.Errorf("Error reading config: %v", err)
}
// Compare the read data with the original data
if readConfig.BaseUrl != testConfig.BaseUrl {
t.Errorf("Expected BaseUrl %s, got %s", testConfig.BaseUrl, readConfig.BaseUrl)
}
}