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

     1  package database
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/drone/drone/pkg/database"
     7  )
     8  
     9  func TestGetBuild(t *testing.T) {
    10  	Setup()
    11  	defer Teardown()
    12  
    13  	build, err := database.GetBuild(1)
    14  	if err != nil {
    15  		t.Error(err)
    16  	}
    17  
    18  	if build.ID != 1 {
    19  		t.Errorf("Exepected ID %d, got %d", 1, build.ID)
    20  	}
    21  
    22  	if build.Slug != "node_0.10" {
    23  		t.Errorf("Exepected Slug %s, got %s", "node_0.10", build.Slug)
    24  	}
    25  
    26  	if build.Status != "Success" {
    27  		t.Errorf("Exepected Status %s, got %s", "Success", build.Status)
    28  	}
    29  }
    30  
    31  func TestGetBuildSlug(t *testing.T) {
    32  	Setup()
    33  	defer Teardown()
    34  
    35  	build, err := database.GetBuildSlug("node_0.10", 1)
    36  	if err != nil {
    37  		t.Error(err)
    38  	}
    39  
    40  	if build.ID != 1 {
    41  		t.Errorf("Exepected ID %d, got %d", 1, build.ID)
    42  	}
    43  
    44  	if build.Slug != "node_0.10" {
    45  		t.Errorf("Exepected Slug %s, got %s", "node_0.10", build.Slug)
    46  	}
    47  
    48  	if build.Status != "Success" {
    49  		t.Errorf("Exepected Status %s, got %s", "Success", build.Status)
    50  	}
    51  }
    52  
    53  func TestSaveBbuild(t *testing.T) {
    54  	Setup()
    55  	defer Teardown()
    56  
    57  	// get the build we plan to update
    58  	build, err := database.GetBuild(1)
    59  	if err != nil {
    60  		t.Error(err)
    61  	}
    62  
    63  	// update fields
    64  	build.Status = "Failing"
    65  
    66  	// update the database
    67  	if err := database.SaveBuild(build); err != nil {
    68  		t.Error(err)
    69  	}
    70  
    71  	// get the updated build
    72  	updatedBuild, err := database.GetBuild(1)
    73  	if err != nil {
    74  		t.Error(err)
    75  	}
    76  
    77  	if build.ID != updatedBuild.ID {
    78  		t.Errorf("Exepected ID %d, got %d", updatedBuild.ID, build.ID)
    79  	}
    80  
    81  	if build.Slug != updatedBuild.Slug {
    82  		t.Errorf("Exepected Slug %s, got %s", updatedBuild.Slug, build.Slug)
    83  	}
    84  
    85  	if build.Status != updatedBuild.Status {
    86  		t.Errorf("Exepected Status %s, got %s", updatedBuild.Status, build.Status)
    87  	}
    88  }
    89  
    90  func TestDeleteBuild(t *testing.T) {
    91  	Setup()
    92  	defer Teardown()
    93  
    94  	if err := database.DeleteBuild(1); err != nil {
    95  		t.Error(err)
    96  	}
    97  
    98  	// try to get the deleted row
    99  	_, err := database.GetBuild(1)
   100  	if err == nil {
   101  		t.Fail()
   102  	}
   103  }
   104  
   105  func TestListBuilds(t *testing.T) {
   106  	Setup()
   107  	defer Teardown()
   108  
   109  	// builds for commit_id = 1
   110  	builds, err := database.ListBuilds(1)
   111  	if err != nil {
   112  		t.Error(err)
   113  	}
   114  
   115  	// verify user count
   116  	if len(builds) != 2 {
   117  		t.Errorf("Exepected %d builds in database, got %d", 2, len(builds))
   118  		return
   119  	}
   120  
   121  	// get the first user in the list and verify
   122  	// fields are being populated correctly
   123  	build := builds[1]
   124  
   125  	if build.ID != 1 {
   126  		t.Errorf("Exepected ID %d, got %d", 1, build.ID)
   127  	}
   128  
   129  	if build.Slug != "node_0.10" {
   130  		t.Errorf("Exepected Slug %s, got %s", "node_0.10", build.Slug)
   131  	}
   132  
   133  	if build.Status != "Success" {
   134  		t.Errorf("Exepected Status %s, got %s", "Success", build.Status)
   135  	}
   136  }