magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.17k stars 256 forks source link

mage and *Testing.T #314

Open harkamals opened 4 years ago

harkamals commented 4 years ago

How can I use mage to run a testing function

// +build mage

package main

import (
    . "fmt"
    "github.com/gruntwork-io/terratest/modules/terraform"
    "testing"
)

// RunMe
func RunMe(t *testing.T) {
    Println("hello mage")
    options := &terraform.Options{
        Parallelism: 1,
    }
    terraform.Init(t, options)
}

$ mage runme Unknown target specified: runme

natefinch commented 4 years ago

I'm not entirely sure why you'd want to do that. Tests already have their own runner. If you put this in a _test.go file, you can run it with go test -run=RunMe

What are you trying to accomplish?

cyberbliss commented 3 years ago

I ran into this same issue too: Gruntwork's terratest modules (like the terraform one) are very useful but, unsurprisingly, expect some kind of *testing.T variable. To get round this in my magefile I did this:

func Run{} {  
   t := testing.T{}  
   options := &terraform.Options{
        Parallelism: 1,
   }
   terraform.Init(&t, options)
}