diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-06-24 16:23:56 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-06-24 16:23:56 -0700 |
| commit | a2ef262a164fc735b9b8471ac0c8001eea2b9bf6 (patch) | |
| tree | 9a24fc5949df1183895a125e09cb262cdf79b073 /hotline/server_test.go | |
| parent | a55350daaf83498b7a237c027ad0dd2377f06fee (diff) | |
Refactoring, cleanup, test backfilling
Diffstat (limited to 'hotline/server_test.go')
| -rw-r--r-- | hotline/server_test.go | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/hotline/server_test.go b/hotline/server_test.go index 6ea8880..a29a4f8 100644 --- a/hotline/server_test.go +++ b/hotline/server_test.go @@ -30,7 +30,7 @@ func TestServer_handleFileTransfer(t *testing.T) { Port int Accounts map[string]*Account Agreement []byte - Clients map[uint16]*ClientConn + Clients map[[2]byte]*ClientConn ThreadedNews *ThreadedNews fileTransfers map[[4]byte]*FileTransfer Config *Config @@ -115,10 +115,10 @@ func TestServer_handleFileTransfer(t *testing.T) { Stats: &Stats{}, fileTransfers: map[[4]byte]*FileTransfer{ {0, 0, 0, 5}: { - ReferenceNumber: []byte{0, 0, 0, 5}, - Type: FileDownload, - FileName: []byte("testfile-8b"), - FilePath: []byte{}, + refNum: [4]byte{0, 0, 0, 5}, + Type: FileDownload, + FileName: []byte("testfile-8b"), + FilePath: []byte{}, ClientConn: &ClientConn{ Account: &Account{ Login: "foo", @@ -190,3 +190,61 @@ func TestServer_handleFileTransfer(t *testing.T) { }) } } + +type TestData struct { + Name string `yaml:"name"` + Value int `yaml:"value"` +} + +func TestLoadFromYAMLFile(t *testing.T) { + tests := []struct { + name string + fileName string + content string + wantData TestData + wantErr bool + }{ + { + name: "Valid YAML file", + fileName: "valid.yaml", + content: "name: Test\nvalue: 123\n", + wantData: TestData{Name: "Test", Value: 123}, + wantErr: false, + }, + { + name: "File not found", + fileName: "nonexistent.yaml", + content: "", + wantData: TestData{}, + wantErr: true, + }, + { + name: "Invalid YAML content", + fileName: "invalid.yaml", + content: "name: Test\nvalue: invalid_int\n", + wantData: TestData{}, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Setup: Create a temporary file with the provided content if content is not empty + if tt.content != "" { + err := os.WriteFile(tt.fileName, []byte(tt.content), 0644) + assert.NoError(t, err) + defer os.Remove(tt.fileName) // Cleanup the file after the test + } + + var data TestData + err := loadFromYAMLFile(tt.fileName, &data) + + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.wantData, data) + } + }) + } +} |