github.com/jimpick/sp-kyc-checks@v0.0.0-20230201194251-fa84fca72da8/internal/testrig/testrig_test.go (about)

     1  package testrig
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"fmt"
     7  	"log"
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func runTestFile(testFile string) []ResponseResult {
    15  	fmt.Printf("Testing %s\n", testFile)
    16  	file := fmt.Sprintf("testdata/%s.json", testFile)
    17  	result, err := RunChecksForFormResponses(context.Background(), file, true)
    18  	if err != nil {
    19  		log.Fatalln(err)
    20  	}
    21  	// fmt.Println(result)
    22  	var results []ResponseResult
    23  	json.Unmarshal([]byte(result), &results)
    24  	return results
    25  }
    26  
    27  func TestResponses(t *testing.T) {
    28  
    29  	if os.Getenv("GOOGLE_MAPS_API_KEY") == "skip" {
    30  		log.Printf("Warning: Skipping tests because GOOGLE_MAPS_API_KEY set to 'skip'")
    31  		return
    32  	}
    33  	os.Chdir("../..")
    34  
    35  	results := runTestFile("responses-1-pass")
    36  	assert.Equal(t, len(results), 1)
    37  	for _, result := range results {
    38  		for _, minerCheckResult := range result.MinerCheckResults {
    39  			assert.True(t, minerCheckResult.Success)
    40  		}
    41  	}
    42  
    43  	results = runTestFile("responses-2-fail-min-power")
    44  	assert.Equal(t, len(results), 1)
    45  	for _, result := range results {
    46  		for _, minerCheckResult := range result.MinerCheckResults {
    47  			assert.False(t, minerCheckResult.Success)
    48  		}
    49  	}
    50  
    51  	results = runTestFile("responses-3-empty")
    52  	assert.Empty(t, results)
    53  
    54  	/*
    55  		results = runTestFile("responses-4-china")
    56  		assert.Equal(t, len(results), 1)
    57  		for _, result := range results {
    58  			for _, minerCheckResult := range result.MinerCheckResults {
    59  				assert.True(t, minerCheckResult.Success)
    60  			}
    61  		}
    62  	*/
    63  
    64  }