...

Source file src/github.com/LINBIT/golinstor/linstortoml/controller_test.go

Documentation: github.com/LINBIT/golinstor/linstortoml

     1  package linstortoml_test
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/BurntSushi/toml"
     8  
     9  	"github.com/LINBIT/golinstor/linstortoml"
    10  )
    11  
    12  func TestController_Write(t *testing.T) {
    13  	cases := []struct {
    14  		config       linstortoml.Controller
    15  		expectedToml string
    16  	}{
    17  		{
    18  			config:       linstortoml.Controller{},
    19  			expectedToml: "",
    20  		},
    21  		{
    22  			config: linstortoml.Controller{
    23  				Db:   &linstortoml.ControllerDb{ConnectionUrl: "https://127.0.0.1:2379", CaCertificate: "/path/to/bundle.pem"},
    24  				Http: &linstortoml.ControllerHttp{Port: 5},
    25  			},
    26  			expectedToml: "[http]\nport = 5\n\n[db]\nconnection_url = \"https://127.0.0.1:2379\"\nca_certificate = \"/path/to/bundle.pem\"\n",
    27  		},
    28  	}
    29  
    30  	for _, test := range cases {
    31  		builder := strings.Builder{}
    32  		enc := toml.NewEncoder(&builder)
    33  		enc.Indent = ""
    34  		err := enc.Encode(test.config)
    35  		if err != nil {
    36  			t.Fatalf("Could not write config: %v", err)
    37  		}
    38  
    39  		result := builder.String()
    40  		if result != test.expectedToml {
    41  			t.Fatalf("Mismatched config, expected '%+v', got '%+v'", test.expectedToml, result)
    42  		}
    43  	}
    44  }
    45  

View as plain text