package jnpf.fileStorage;
|
|
import io.minio.BucketExistsArgs;
|
import io.minio.MinioClient;
|
import org.dromara.x.file.storage.core.platform.MinioFileStorage;
|
import org.junit.Test;
|
|
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertTrue;
|
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.when;
|
|
public class SeaweedFsBucketVerifierTest {
|
|
@Test
|
public void acceptsAccessibleBucket() throws Exception {
|
MinioFileStorage storage = storageWithBucketResult(true);
|
|
new SeaweedFsBucketVerifier().verify(storage);
|
}
|
|
@Test
|
public void rejectsMissingBucket() throws Exception {
|
MinioFileStorage storage = storageWithBucketResult(false);
|
|
IllegalStateException exception = assertThrows(IllegalStateException.class,
|
() -> new SeaweedFsBucketVerifier().verify(storage));
|
|
assertTrue(exception.getMessage().contains("jnpf-common"));
|
}
|
|
@Test
|
public void reportsInaccessibleBucket() throws Exception {
|
MinioFileStorage storage = mock(MinioFileStorage.class);
|
MinioClient client = mock(MinioClient.class);
|
when(storage.getBucketName()).thenReturn("jnpf-common");
|
when(storage.getClient()).thenReturn(client);
|
when(client.bucketExists(any(BucketExistsArgs.class)))
|
.thenThrow(new IllegalArgumentException("connection failed"));
|
|
IllegalStateException exception = assertThrows(IllegalStateException.class,
|
() -> new SeaweedFsBucketVerifier().verify(storage));
|
|
assertTrue(exception.getMessage().contains("无法访问"));
|
assertTrue(exception.getCause() instanceof IllegalArgumentException);
|
}
|
|
private MinioFileStorage storageWithBucketResult(boolean exists) throws Exception {
|
MinioFileStorage storage = mock(MinioFileStorage.class);
|
MinioClient client = mock(MinioClient.class);
|
when(storage.getBucketName()).thenReturn("jnpf-common");
|
when(storage.getClient()).thenReturn(client);
|
when(client.bucketExists(any(BucketExistsArgs.class))).thenReturn(exists);
|
return storage;
|
}
|
}
|