feedback/internal/config/config_test.go
2023-04-20 07:03:21 +05:00

50 lines
959 B
Go

package config
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestNewConfig(t *testing.T) {
tests := []struct {
name string
args string
withError bool
want any
}{
{
name: "equal",
args: "test.env",
want: &Config{
TelegramToken: "6016088135:AAH3KFBfsi5ivoS0bF9f0p6j28HNuwoBNn0",
TelegramChannelID: -1001957127019,
TemplatePath: "assets/template_msg.txt",
HttpRateLimit: 30 * time.Second,
HttpAddress: ":80",
},
},
{
name: "error no file",
args: "not-found.env",
withError: true,
want: "open no-test.env: The system cannot find the file specified.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewConfig(tt.args)
if tt.withError {
assert.Equal(t, err.Error(), tt.want)
} else {
if assert.NoError(t, err) {
assert.Equal(t, tt.want, got)
}
}
})
}
}