github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/cd-service/pkg/sqlitestore/sqlitestore_test.go (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  
    17  package sqlitestore
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  	git "github.com/libgit2/git2go/v34"
    24  )
    25  
    26  func TestWriteAndRead(t *testing.T) {
    27  	be, err := NewOdbBackend(":memory:")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	odb, err := git.NewOdb()
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	err = odb.AddBackend(be, 0)
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	data := "foo"
    40  	oid, err := odb.Write([]byte(data), git.ObjectBlob)
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  	result, err := odb.Read(oid)
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if diff := cmp.Diff(data, string(result.Data())); diff != "" {
    49  		t.Errorf("result mismatch (-want, +got):\n%s", diff)
    50  	}
    51  }