Select Git revision
api_test.go
api_test.go 1.09 KiB
// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package configuration
import (
"github.com/stretchr/testify/assert"
"testing"
)
// Example for README
// Print are commented out because they are only for demonstration
func TestReadExample1(t *testing.T) {
config := struct {
Host string
Port int
}{
Host: "localhost",
Port: 8080,
}
c := New(config)
//fmt.Println(c.Config().Host)
//fmt.Println(c.Config().Port)
assert.Equal(t, c.Config().Host, "localhost")
assert.Equal(t, c.Config().Port, 8080)
}
func TestNew(t *testing.T) {
var config ConfigStruct2
s := New(config)
if s == nil {
t.Error("Expected not nil")
}
}
func TestNewWithDefaults(t *testing.T) {
var config ConfigStruct2
s := New(config)
if s == nil {
t.Error("Expected not nil")
}
// use external api to read the value
if s.Config().H.HA != 1 {
t.Error("Expected 1")
}
// use internal api to read the value
if s.config.H.HB != "yes" {
t.Error("Expected yes")
}
if s.config.H.HC != true {
t.Error("Expected true")
}
if s.config.H.HD != false {
t.Error("Expected false")
}
}