diff --git a/sda-admin/list/list_test.go b/sda-admin/list/list_test.go index 1276a408a..a529c870a 100644 --- a/sda-admin/list/list_test.go +++ b/sda-admin/list/list_test.go @@ -1,7 +1,6 @@ package list import ( - "errors" "testing" "github.com/neicnordic/sensitive-data-archive/sda-admin/helpers" @@ -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) @@ -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) @@ -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) -}