diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..593d1a0 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,19 @@ +name: fluence testing + +on: + pull_request: [] + +jobs: + test-fluence: + runs-on: ubuntu-latest + name: build fluence + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ^1.21 + + - name: Run Tests + run: | + cd src/fluence + make test \ No newline at end of file diff --git a/src/fluence/Makefile b/src/fluence/Makefile new file mode 100644 index 0000000..9e56215 --- /dev/null +++ b/src/fluence/Makefile @@ -0,0 +1,7 @@ + +.PHONY: all +all: test + +.PHONY: test +test: + go test -v ./jgf/ \ No newline at end of file diff --git a/src/fluence/jgf/jgf_test.go b/src/fluence/jgf/jgf_test.go new file mode 100644 index 0000000..c705a48 --- /dev/null +++ b/src/fluence/jgf/jgf_test.go @@ -0,0 +1,77 @@ +package jgf + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewFluxJGF(t *testing.T) { + + // Create a new FluxGraph, assert that it is empty + fluxgraph := NewFluxJGF() + assert.Equal(t, len(fluxgraph.Graph.Nodes), 0) + assert.Equal(t, fluxgraph.Resources.Elements, int64(0)) + assert.Equal(t, len(fluxgraph.NodeMap), 0) + + out, err := fluxgraph.ToJson() + assert.Nil(t, err) + fmt.Println() + fmt.Println("== Empty graph:") + fmt.Println(out) + + // Init the cluster (make the root node) + clusterNode, err := fluxgraph.InitCluster("keebler") + assert.Nil(t, err) + + out, err = fluxgraph.ToJson() + assert.Nil(t, err) + fmt.Println() + fmt.Println("== Graph with Cluster Root:") + fmt.Println(out) + + // Add subnets to it + subnetNodeA := fluxgraph.MakeSubnet("east") + subnetNodeB := fluxgraph.MakeSubnet("west") + fluxgraph.MakeBidirectionalEdge(clusterNode.Id, subnetNodeA.Id) + fluxgraph.MakeBidirectionalEdge(clusterNode.Id, subnetNodeB.Id) + + out, err = fluxgraph.ToJson() + assert.Nil(t, err) + fmt.Println() + fmt.Println("== Graph with Two Subnets:") + fmt.Println(out) + + // Add some nodes! + computeNodeA := fluxgraph.MakeNode("node", subnetNodeA.Metadata.Name) + computeNodeB := fluxgraph.MakeNode("node", subnetNodeB.Metadata.Name) + fluxgraph.MakeBidirectionalEdge(subnetNodeA.Id, computeNodeA.Id) + fluxgraph.MakeBidirectionalEdge(subnetNodeB.Id, computeNodeB.Id) + + out, err = fluxgraph.ToJson() + assert.Nil(t, err) + fmt.Println() + fmt.Println("== Graph with Two Subnets, Each with a node:") + fmt.Println(out) + + // Add a GPU to one, and cores to the other + subpath := fmt.Sprintf("%s/%s", subnetNodeA.Metadata.Name, computeNodeA.Metadata.Name) + gpuNodeA := fluxgraph.MakeGPU(NvidiaGPU, subpath, 1) + fluxgraph.MakeBidirectionalEdge(computeNodeA.Id, gpuNodeA.Id) + + subpath = fmt.Sprintf("%s/%s", subnetNodeB.Metadata.Name, computeNodeB.Metadata.Name) + coreNode := fluxgraph.MakeCore(CoreType, subpath) + fluxgraph.MakeBidirectionalEdge(computeNodeB.Id, coreNode.Id) + + // Finally, add some memory to the second compute node + memoryNode := fluxgraph.MakeMemory(MemoryType, subpath, 1<<10) + fluxgraph.MakeBidirectionalEdge(computeNodeA.Id, memoryNode.Id) + + out, err = fluxgraph.ToJson() + assert.Nil(t, err) + fmt.Println() + fmt.Println("== Graph with Two Subnets, Two Nodes, with GPU/Core/Memory:") + fmt.Println(out) + +}