github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/testing/settings_test.go (about)

     1  package database
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/drone/drone/pkg/database"
     7  )
     8  
     9  func TestGetSettings(t *testing.T) {
    10  	Setup()
    11  	defer Teardown()
    12  
    13  	// even though no settings exist yet, we should
    14  	// not see an error since we supress the msg
    15  	settings, err := database.GetSettings()
    16  	//if err != nil {
    17  	//	t.Error(err)
    18  	//}
    19  
    20  	// add some settings
    21  	//settings := &modelSettings{}
    22  	settings.Scheme = "https"
    23  	settings.Domain = "foo.com"
    24  	settings.BitbucketKey = "bitbucketkey"
    25  	settings.BitbucketSecret = "bitbucketsecret"
    26  	settings.GitHubKey = "githubkey"
    27  	settings.GitHubSecret = "githubsecret"
    28  	settings.SmtpAddress = "noreply@foo.bar"
    29  	settings.SmtpServer = "0.0.0.0"
    30  	settings.SmtpUsername = "username"
    31  	settings.SmtpPassword = "password"
    32  
    33  	// save the updated settings
    34  	if err := database.SaveSettings(settings); err != nil {
    35  		t.Error(err)
    36  	}
    37  
    38  	// re-retrieve the settings post-save
    39  	settings, err = database.GetSettings()
    40  	if err != nil {
    41  		t.Error(err)
    42  	}
    43  
    44  	if settings.ID != 1 {
    45  		t.Errorf("Exepected ID %d, got %d", 1, settings.ID)
    46  	}
    47  
    48  	if settings.Scheme != "https" {
    49  		t.Errorf("Exepected Scheme %s, got %s", "https", settings.Scheme)
    50  	}
    51  
    52  	if settings.Domain != "foo.com" {
    53  		t.Errorf("Exepected Domain %s, got %s", "foo.com", settings.Domain)
    54  	}
    55  
    56  	// Verify caching works and is threadsafe
    57  	settingsA, _ := database.GetSettings()
    58  	settingsB, _ := database.GetSettings()
    59  	settingsA.Domain = "foo.bar.baz"
    60  	if settingsA.Domain == settingsB.Domain {
    61  		t.Errorf("Exepected Domain ThreadSafe and unchanged")
    62  	}
    63  }