github.com/abayer/test-infra@v0.0.5/velodrome/sql/testing/sqlite_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package testing
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  	"time"
    23  
    24  	"k8s.io/test-infra/velodrome/sql"
    25  )
    26  
    27  func TestSQLiteCreateDatabase(t *testing.T) {
    28  	config := SQLiteConfig{":memory:"}
    29  	db, err := config.CreateDatabase()
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  
    34  	issue := sql.Issue{
    35  		ID:             "1",
    36  		Repository:     "Repo",
    37  		Labels:         nil,
    38  		Title:          "Title",
    39  		Body:           "Body",
    40  		User:           "JohnDoe",
    41  		State:          "State",
    42  		Comments:       0,
    43  		IsPR:           true,
    44  		IssueUpdatedAt: time.Date(1900, time.January, 1, 12, 0, 0, 0, time.UTC),
    45  		IssueCreatedAt: time.Date(1900, time.January, 1, 12, 0, 0, 0, time.UTC),
    46  	}
    47  
    48  	if err := db.Create(&issue).Error; err != nil {
    49  		t.Fatal(err)
    50  	}
    51  	var foundIssue sql.Issue
    52  	if err := db.First(&foundIssue).Error; err != nil {
    53  		t.Fatal(err)
    54  	}
    55  	if !reflect.DeepEqual(foundIssue, issue) {
    56  		t.Fatal("FoundIssue:", foundIssue,
    57  			"is different from inserted issue:", issue)
    58  	}
    59  	issue.Body = "Super Body"
    60  	if err := db.Save(&issue).Error; err != nil {
    61  		t.Fatal(err)
    62  	}
    63  	if err := db.First(&foundIssue).Error; err != nil {
    64  		t.Fatal(err)
    65  	}
    66  	if !reflect.DeepEqual(foundIssue, issue) {
    67  		t.Fatal("FoundIssue:", foundIssue,
    68  			"is different from updated issue:", issue)
    69  	}
    70  }