We'll divide this part into 5 sections:
- Creating lab metadata
- Setting up lab defaults
- Setting up lab challenges
- Setting up evaluation script
- Setting up test file
This guide would assume that you already have created an interactive course from your instructor panel. If not, go here and set it up first
Lab details is the tab where you add two important things:
- Lab title
- Lab description
Once both of them are filled, it would appear as following:
Let's move to the next tab now.
Container image should be set as Golang. Container image is a hint for us to know ahead of time what the primary language of your lab would be.
Lab defaults section include how your lab environment boots. It is one of the most important parts because a wrong default environment might confuse your students. Therefore it is important to set it up properly.
When a codedamn playground boots, it can setup a filesystem for user by default. You can specify what the starting files could be, by specifying a git repository and a branch name:
:::info
You will find a .cdmrc file in the repository given to you above. It is highly recommend, at this point, that you go through the .cdmrc guide and how to use .cdmrc in playgrounds to understand what .cdmrc file exactly is. Once you understand how to work with .cdmrc come back to this area.
:::
Evaluation script is actually what runs when the user on the codedamn playground clicks on "Run Tests" button.
We have to write a boolean array to the file $UNIT_TEST_OUTPUT_FILE. Since go already has a builtin testing utility, we can use that as follows:
#!/bin/bash
set -e 1
mv $TEST_FILE_NAME /home/damner/code/codedamn_evaluation_test.go
# run test
cd /home/damner/code
go mod init codedamn # assuming you used "codedamn" as the package
go test -json -parallel 1 > codedamn_evaluation_output.json || true
# process results file
cat > processGoResults.js << EOF
const fs = require('fs')
// Read the test results file into memory as a string
const testResults = fs.readFileSync('./codedamn_evaluation_output.json', 'utf8').filter(Boolean)
const lines = testResults.split('\n')
// Create an empty array to store the pass/fail status of each test
const results = []
// Loop through each line and parse it as JSON and check if it is a result line
lines.forEach(line => {
const output = JSON.parse(line).Output?.trim()
const valid = output === 'PASS' || output === 'FAIL'
if(!valid) return
const passed = output === 'PASS'
// Add the pass/fail status to the array
results.push(passed)
})
// Write results
fs.writeFileSync(process.env.UNIT_TEST_OUTPUT_FILE, JSON.stringify(results))
EOF
# process results
node processGoResults.js
# remove files
rm /home/damner/code/codedamn_evaluation_test.go codedamn_evaluation_output.json processGoResults.jsLet's explain what's going on here:
- We copy our test script (that we will write in next step) in the same directory as user code
/home/damner/code. This way we can access user packages comfortably. - We run
go mod initsincego.modfile is required to be present when you rungo testutility. If you have already created ago.modfile (in the default repository file setup), this command would do nothing - We now run
go testwith-jsonand-parallel 1flag. We needjsonflag as we will parse it using a simple Node.js script written later. You can use Go for that parsing too (if you can write an equivalent). We need-parallel 1so that we process the tests in correct order (since the mapping of the boolean array here is linked to how tests would appear on frontend). - Go's test util output is stored in a file called
codedamn_evaluation_output.json. This file technically is not a valid JSON since Go streams all output as individual JSON objects. - We finally run the Node.js script that splits the file
codedamn_evaluation_output.jsonby newline. We parse individual lines as JSON and only process the objects where the.Outputfield in JSON is eitherPASSorFAIL. - Since we have
-parallel 1, the output order would be preserved on how you wrote the tests. - We store this boolean array into the
$UNIT_TEST_OUTPUT_FILEwhich is then visible to the end user.
Note: Be careful with the package imports in go, package name and test file location.
You will see a button named Edit Test File in the Evaluation tab. Click on it.
When you click on it, a new window will open. This is a test file area.
You can write anything here. Whatever script you write here, can be executed from the Test command to run section inside the evaluation tab we were in earlier.
The point of having a file like this to provide you with a place where you can write your evaluation script. As we decided earlier, you can write a simple Go test here:
package codedamn
import "testing"
func TestAdd(t *testing.T) {
got := add(2, 3)
if got != 5 {
t.Errorf("add(2, 3) = %d; want 5", got)
}
}This file contains only one test at the moment that would give JSON output stream that will be processed further by our Node.js script earlier. This completes your evaluation script for the lab. Your lab is now almost ready for users.




