github.com/andrewrech/ih-abstract@v0.0.0-20210322142951-2fec1c8d0f38/config_test.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/google/go-cmp/cmp"
     9  )
    10  
    11  func TestLocateConfig(t *testing.T) {
    12  	os.Setenv("XDG_CONFIG_HOME", "ih-abstractTestdirectory")
    13  	os.Setenv("HOME", "ih-abstractTestdirectory")
    14  
    15  	f, _ := locateDefaultConfig()
    16  
    17  	if f != "" {
    18  		t.Error("", f)
    19  	}
    20  }
    21  
    22  func TestLoadConfig(t *testing.T) {
    23  	vars, err := loadConfig("ih-abstract.yml")
    24  	if err != nil {
    25  		log.Fatalln(err)
    26  	}
    27  
    28  	tests := map[string]struct {
    29  		got  string
    30  		want string
    31  	}{
    32  		"Username": {got: vars.Username, want: "username"},
    33  		"Password": {got: vars.Password, want: "password"},
    34  		"Host":     {got: vars.Host, want: "0.0.0.0"},
    35  		"Port":     {got: vars.Port, want: "80"},
    36  		"Database": {got: vars.Database, want: "database"},
    37  		"Query":    {got: vars.Query, want: "SELECT TOP (5) * FROM [database].[xx].[xx]"},
    38  	}
    39  
    40  	for name, tc := range tests {
    41  		name := name
    42  		tc := tc
    43  
    44  		t.Run(name, func(t *testing.T) {
    45  			got := tc.got
    46  
    47  			diff := cmp.Diff(tc.want, got)
    48  			if diff != "" {
    49  				t.Fatalf(diff)
    50  			}
    51  		})
    52  	}
    53  }