Skip to content

Commit

Permalink
remove irrelevant unit tests suggested by jocke
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjiangshu committed Sep 4, 2024
1 parent a5d7c2a commit 44dba87
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions sda-admin/list/list_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package list

import (
"errors"
"testing"

"github.com/neicnordic/sensitive-data-archive/sda-admin/helpers"
Expand All @@ -20,7 +19,7 @@ func (m *MockHelpers) GetResponseBody(url, token string) ([]byte, error) {
return args.Get(0).([]byte), args.Error(1)
}

func TestListUsers_Success(t *testing.T) {
func TestListUsers(t *testing.T) {
mockHelpers := new(MockHelpers)
mockHelpers.On("GetResponseBody", "http://example.com/users", "test-token").Return([]byte(`["user1", "user2"]`), nil)

Expand All @@ -34,36 +33,7 @@ func TestListUsers_Success(t *testing.T) {
mockHelpers.AssertExpectations(t)
}

func TestListUsers_Failure(t *testing.T) {
mockHelpers := new(MockHelpers)
mockHelpers.On("GetResponseBody", "http://example.com/users", "test-token").Return([]byte(nil), errors.New("failed to get users"))

// Replace the original GetResponseBody with the mock
originalFunc := helpers.GetResponseBody
defer func() { helpers.GetResponseBody = originalFunc }()
helpers.GetResponseBody = mockHelpers.GetResponseBody

err := ListUsers("http://example.com", "test-token")
assert.Error(t, err)
assert.EqualError(t, err, "failed to get users")
mockHelpers.AssertExpectations(t)
}

func TestListFiles_NoUsername_Success(t *testing.T) {
mockHelpers := new(MockHelpers)
mockHelpers.On("GetResponseBody", "http://example.com/files", "test-token").Return([]byte(`["file1", "file2"]`), nil)

// Replace the original GetResponseBody with the mock
originalFunc := helpers.GetResponseBody
defer func() { helpers.GetResponseBody = originalFunc }()
helpers.GetResponseBody = mockHelpers.GetResponseBody

err := ListFiles("http://example.com", "test-token", "")
assert.NoError(t, err)
mockHelpers.AssertExpectations(t)
}

func TestListFiles_WithUsername_Success(t *testing.T) {
func TestListFiles(t *testing.T) {
mockHelpers := new(MockHelpers)
mockHelpers.On("GetResponseBody", "http://example.com/users/testuser/files", "test-token").Return([]byte(`["file1", "file2"]`), nil)

Expand All @@ -76,18 +46,3 @@ func TestListFiles_WithUsername_Success(t *testing.T) {
assert.NoError(t, err)
mockHelpers.AssertExpectations(t)
}

func TestListFiles_Failure(t *testing.T) {
mockHelpers := new(MockHelpers)
mockHelpers.On("GetResponseBody", "http://example.com/files", "test-token").Return([]byte(nil), errors.New("failed to get files"))

// Replace the original GetResponseBody with the mock
originalFunc := helpers.GetResponseBody
defer func() { helpers.GetResponseBody = originalFunc }()
helpers.GetResponseBody = mockHelpers.GetResponseBody

err := ListFiles("http://example.com", "test-token", "")
assert.Error(t, err)
assert.EqualError(t, err, "failed to get files")
mockHelpers.AssertExpectations(t)
}

0 comments on commit 44dba87

Please sign in to comment.