From 4fd22dc131dbe5bb26ac3a3fe5abc8000c4b1e80 Mon Sep 17 00:00:00 2001 From: pb Date: Wed, 17 Jul 2024 17:19:03 +0200 Subject: [PATCH] tests for each model --- data_test.go | 39 +++++++++++++++++++++++++++++++++++++- datacenter_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++++ processing_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ storage_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ workflow_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 datacenter_test.go create mode 100644 processing_test.go create mode 100644 storage_test.go create mode 100644 workflow_test.go diff --git a/data_test.go b/data_test.go index 163d7dc..46d83fc 100644 --- a/data_test.go +++ b/data_test.go @@ -2,8 +2,45 @@ package oclib import ( "testing" + + "github.com/stretchr/testify/assert" ) -func TestPostOneData(t *testing.T){ +func TestStoreOneData(t *testing.T){ + d := Data{DataType: "jpeg", Example: "123456", + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + dma := DataMongoAccessor{} + id := dma.StoreOne(d) + + assert.NotEmpty(t, id) +} + +func TestLoadOneDate(t *testing.T){ + d := Data{DataType: "jpeg", Example: "123456", + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + dma := DataMongoAccessor{} + id := dma.StoreOne(d) + new_d := dma.LoadOne(id) + + assert.Equal(t,d, new_d) } \ No newline at end of file diff --git a/datacenter_test.go b/datacenter_test.go new file mode 100644 index 0000000..0a64a86 --- /dev/null +++ b/datacenter_test.go @@ -0,0 +1,46 @@ +package oclib + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStoreOneDatacenter(t *testing.T){ + dc := Datacenter{Owner: "toto", BookingPrice: 123, + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testDatacenter", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + dcma := DatacenterMongoAccessor{} + id := dcma.StoreOne(dc) + + assert.NotEmpty(t, id) +} + +func TestLoadOneDatacenter(t *testing.T){ + dc := Datacenter{Owner: "toto", BookingPrice: 123, + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testDatacenter", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + dcma := DatacenterMongoAccessor{} + id := dcma.StoreOne(dc) + new_dc := dcma.LoadOne(id) + + assert.Equal(t,dc, new_dc) +} \ No newline at end of file diff --git a/processing_test.go b/processing_test.go new file mode 100644 index 0000000..8fa15d9 --- /dev/null +++ b/processing_test.go @@ -0,0 +1,47 @@ +package oclib + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStoreOneProcessing(t *testing.T){ + p := Processing{ Container: "totoCont", + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + sma := ProcessingMongoAccessor{} + id := sma.StoreOne(p) + + assert.NotEmpty(t, id) +} + +func TestLoadOneProcessing(t *testing.T){ + p := Processing{ Container: "totoCont", + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + + sma := ProcessingMongoAccessor{} + id := sma.StoreOne(p) + new_s := sma.LoadOne(id) + + assert.Equal(t,p, new_s) +} \ No newline at end of file diff --git a/storage_test.go b/storage_test.go new file mode 100644 index 0000000..a784ed9 --- /dev/null +++ b/storage_test.go @@ -0,0 +1,47 @@ +package oclib + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStoreOneStorage(t *testing.T){ + s := Storage{ Capacity: 123, Url: URL{Protocol: "http",Path: "azerty.fr"} , + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + sma := StorageMongoAccessor{} + id := sma.StoreOne(s) + + assert.NotEmpty(t, id) +} + +func TestLoadOneStorage(t *testing.T){ + s := Storage{ Capacity: 123, Url: URL{Protocol: "http",Path: "azerty.fr"} , + AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testData", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + + sma := StorageMongoAccessor{} + id := sma.StoreOne(s) + new_s := sma.LoadOne(id) + + assert.Equal(t,s, new_s) +} \ No newline at end of file diff --git a/workflow_test.go b/workflow_test.go new file mode 100644 index 0000000..8c5e93a --- /dev/null +++ b/workflow_test.go @@ -0,0 +1,44 @@ +package oclib + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStoreOneWorkflow(t *testing.T){ + w := Workflow{AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testWorkflow", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + wma := WorkflowMongoAccessor{} + id := wma.StoreOne(w) + + assert.NotEmpty(t, id) +} + +func TestLoadOneWorkflow(t *testing.T){ + w := Workflow{AbstractResource: AbstractResource{ + Uuid: "123", + Name: "testWorkflow", + Description: "Lorem Ipsum", + Logo : "azerty.com", + Owner: "toto", + OwnerLogo: "totoLogo", + SourceUrl: "azerty.fr", + }, + } + + wma := WorkflowMongoAccessor{} + id := wma.StoreOne(w) + new_w := wma.LoadOne(id) + + assert.Equal(t,w, new_w) +} \ No newline at end of file