-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages_test.go
More file actions
55 lines (50 loc) · 1.49 KB
/
messages_test.go
File metadata and controls
55 lines (50 loc) · 1.49 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
/*
* Copyright 2022-2026 Thorsten A. Knieling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
package services
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMessages(t *testing.T) {
denv := os.Getenv("ADADATADIR")
assert.NotEqual(t, "ABCxyz", denv)
os.Setenv("ADADATADIR", "ABCxyz")
e := os.ExpandEnv("${ADADATADIR}")
assert.Equal(t, "ABCxyz", e)
e = os.ExpandEnv("rrr${ADADATADIR}yyy")
assert.Equal(t, "rrrABCxyzyyy", e)
os.Setenv("CURDIR", "CCCCCC")
e = os.ExpandEnv("${CURDIR}")
assert.Equal(t, "CCCCCC", e)
e = os.ExpandEnv("abc${CURDIR}def")
assert.Equal(t, "abcCCCCCCdef", e)
e = os.ExpandEnv("abc${CURDIR}def${ADADATADIR}aa")
assert.Equal(t, "abcCCCCCCdefABCxyzaa", e)
}
func TestLogMessages(t *testing.T) {
os.Remove(os.ExpandEnv("${LOGPATH}/x"))
os.Remove(os.ExpandEnv("${LOGPATH}/x.1"))
os.Remove(os.ExpandEnv("${LOGPATH}/x.2"))
os.Remove(os.ExpandEnv("${LOGPATH}/x.3"))
logging := new(Logging)
logging.ServerLocation = "${LOGPATH}/x"
logging.OpenMessageLog()
ServerMessage("ABC")
CloseMessageLog()
logging.ServerLocation = "${LOGPATH}/x"
logging.OpenMessageLog()
ServerMessage("XYZ")
ServerMessage("ZZZ")
assert.FileExists(t, os.ExpandEnv("${LOGPATH}/x"))
assert.FileExists(t, os.ExpandEnv("${LOGPATH}/x.1"))
assert.NoFileExists(t, os.ExpandEnv("${LOGPATH}/x.2"))
}