Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate the data file instead #28

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package file_test
import (
"context"
"crypto/sha256"
"os"
"path"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -63,7 +65,21 @@ func (*fakePutClient) CloseSend() error {
return nil
}

func generateFile(t *testing.T, data string) string {
// Create a temporary file
fileName := path.Join(t.TempDir(), "data")

// Write some text to the file
if err := os.WriteFile(fileName, []byte(data), 0644); err != nil {
t.Fatalf("unable to write temp file contents: %v", err)
}

return fileName
}

func TestPut(t *testing.T) {
const data = "some really important data"
fileName := generateFile(t, data)
alshabib marked this conversation as resolved.
Show resolved Hide resolved
hash := sha256.New()
_, err := hash.Write([]byte(`some really important data`))
if err != nil {
Expand All @@ -82,7 +98,7 @@ func TestPut(t *testing.T) {
},
{
desc: "put-with-file",
op: file.NewPutOperation().SourceFile("testdata/data.txt"),
op: file.NewPutOperation().SourceFile(fileName),
wantReq: []*fpb.PutRequest{
{
Request: &fpb.PutRequest_Open{
Expand All @@ -91,7 +107,7 @@ func TestPut(t *testing.T) {
},
{
Request: &fpb.PutRequest_Contents{
Contents: []byte(`some really important data`),
Contents: []byte(data),
},
},
{
Expand All @@ -106,7 +122,7 @@ func TestPut(t *testing.T) {
},
{
desc: "put-with-all-details",
op: file.NewPutOperation().SourceFile("testdata/data.txt").RemoteFile("/tmp/here").Perms(644),
op: file.NewPutOperation().SourceFile(fileName).RemoteFile("/tmp/here").Perms(644),
wantReq: []*fpb.PutRequest{
{
Request: &fpb.PutRequest_Open{
Expand All @@ -118,7 +134,7 @@ func TestPut(t *testing.T) {
},
{
Request: &fpb.PutRequest_Contents{
Contents: []byte(`some really important data`),
Contents: []byte(data),
},
},
{
Expand Down
1 change: 0 additions & 1 deletion file/testdata/data.txt

This file was deleted.

Loading