Skip to content
Snippets Groups Projects
Select Git revision
  • 1b4021d0dacaacc8c8670ead0a535c84279cc96b
  • master default protected
  • v1.22.9
  • v1.22.8
  • v1.22.7
  • v1.22.6
  • v1.22.5
  • v1.22.4
  • v1.22.3
  • v1.22.1
  • v1.22.0
  • v1.21.0
  • v1.20.5
  • v1.20.4
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.0
  • v1.18.3
  • v1.18.2
  • v1.18.1
22 results

api_test.go

Blame
  • 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")
    	}
    
    }